ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 22.11.2023
Просмотров: 189
Скачиваний: 8
ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.
Рисунок 36 – Детали с ценой не ниже средней
-
SELECT "Detail".id, "Detail".Name, "Detail"."Price", "Detail"."Weight", -
"Detail"."Color", "Detail"."High cost", SUM("Amount" * "Price") AS allprice FROM "Detail", "Delivery" -
WHERE "Detail".id = "Delivery"."Detail_ID" AND -
"Price" = (SELECT MAX("Price") FROM "Detail") -
GROUP BY "Detail".id;
Рисунок 37 – Детали с максимальной ценой
-
SELECT "Detail".id, "Detail".Name, "Detail"."Price", "Detail"."Weight", -
"Detail"."Color", "Detail"."High cost", SUM("Amount" * "Price") AS allprice FROM "Detail", "Delivery" -
WHERE "Detail".id = "Delivery"."Detail_ID" AND -
"Price" = (SELECT MIN("Price") FROM "Detail") -
GROUP BY "Detail".id;
Рисунок 38 – Детали с минимальной ценой
3. Список всех проектов, список проектов с бюджетом не ниже/не выше среднего, список проектов с максимальным/минимальным бюджетом – с указанием общей суммы поставок по данному проекту (непременное условие для всех списков):
-
SELECT "Project".id, "Project".name, "Project"."City", -
"Project"."Address", "Project"."Budget", SUM("Amount" * "Price") AS "All Price" -
FROM "Project", "Delivery", "Detail" -
WHERE "Delivery"."Project_ID" = "Project".id -
AND "Delivery"."Detail_ID" = "Detail".id -
GROUP BY "Project".id -
ORDER BY id;
Рисунок 39 – Все проекты
-
SELECT "Project".id, "Project".name, "Project"."City", -
"Project"."Address", "Project"."Budget", SUM("Amount" * "Price") AS "All Price" -
FROM "Project","Delivery","Detail" -
WHERE "Delivery"."Project_ID" = "Project".id -
AND "Delivery"."Detail_ID" = "Detail".id -
AND "Budget" <= (SELECT MAX("Budget") FROM "Project")/2 -
GROUP BY "Project".id -
ORDER BY "Project".id;
Рисунок 40 – Проекты с бюджетом ниже среднего
-
SELECT "Project".id, "Project".name, "Project"."City", -
"Project"."Address", "Project"."Budget", SUM("Amount" * "Price") AS "All Price" -
FROM "Project","Delivery","Detail" -
WHERE "Delivery"."Project_ID" = "Project".id -
AND "Delivery"."Detail_ID" = "Detail".id -
AND "Budget" >= (SELECT MAX("Budget") FROM "Project")/2 -
GROUP BY "Project".id -
ORDER BY "Project".id;
Рисунок 41 – Проекты с бюджетом выше среднего
-
SELECT "Project".id, "Project".name, "Project"."City", -
"Project"."Address", "Project"."Budget", SUM("Amount" * "Price") AS "All Price" -
FROM "Project","Delivery","Detail" -
WHERE "Delivery"."Project_ID" = "Project".id -
AND "Delivery"."Detail_ID" = "Detail".id -
AND "Budget" = (SELECT MAX("Budget") FROM "Project") -
GROUP BY "Project".id;
Рисунок 42 – Проекты с максимальным бюджетом
-
SELECT "Project".id, "Project".name, "Project"."City", -
"Project"."Address", "Project"."Budget", SUM("Amount" * "Price") AS "All Price" -
FROM "Project","Delivery","Detail" -
WHERE "Delivery"."Project_ID" = "Project".id -
AND "Delivery"."Detail_ID" = "Detail".id -
AND "Budget" = (SELECT MIN("Budget") FROM "Project") -
GROUP BY "Project".id;
Рисунок 43 – Проекты с минимальным бюджетом
4. Сумма всех поставок, сумма поставок дорогих деталей, сумма поставок дешевых деталей, сумма поставок от надежных поставщиков, сумма поставок от ненадежных поставщиков, сумма поставок от заданного поставщика:
-
SELECT COUNT(*) FROM "Delivery";
Рисунок 44 – Сумма всех поставок
-
SELECT "Detail".Name,"Detail".id,COUNT(*), SUM("Delivery"."Amount" * "Detail"."Price") AS "All Price" -
FROM "Delivery" INNER JOIN "Detail" -
ON "Delivery"."Detail_ID" = "Detail".id -
AND "Detail"."High cost" = 'Дорогая' -
GROUP BY "Detail".id;
Рисунок 45 – Поставки дорогих деталей
-
SELECT "Detail".Name,"Detail".id,COUNT(*), SUM("Delivery"."Amount" * "Detail"."Price") AS "All Price" -
FROM "Delivery" INNER JOIN "Detail" -
ON "Delivery"."Detail_ID" = "Detail".id -
AND "Detail"."High cost" = 'Дешёвая' -
GROUP BY "Detail".id;
Рисунок 46 – Поставки дешёвых деталей
-
SELECT COUNT(*),"Contractor".Name, "Contractor".id, SUM("Delivery"."Amount" * "Detail"."Price") AS "All Price" -
FROM "Delivery", "Detail", "Contractor" -
WHERE "Delivery"."Detail_ID" = "Detail".id AND "Delivery"."Contractor_ID" = "Contractor".id -
AND "Contractor"."Reliability" = 'Надёжный' -
GROUP BY "Contractor".id;
Рисунок 47 – Поставки от надежных поставщиков
-
SELECT COUNT(*),"Contractor".Name, "Contractor".id, SUM("Delivery"."Amount" * "Detail"."Price") AS "All Price" -
FROM "Delivery", "Detail", "Contractor" -
WHERE "Delivery"."Detail_ID" = "Detail".id AND "Delivery"."Contractor_ID" = "Contractor".id -
AND "Contractor"."Reliability" = 'Ненадёжный' -
GROUP BY "Contractor".id;
Рисунок 48 – Поставки от ненадежных поставщиков
-
SELECT COUNT(*),"Contractor".Name, "Contractor".id, SUM("Delivery"."Amount" * "Detail"."Price") AS "All Price" -
FROM "Delivery", "Detail", "Contractor" -
WHERE "Delivery"."Detail_ID" = "Detail".id AND "Delivery"."Contractor_ID" = "Contractor".id -
AND "Contractor".name = 'Company 6' -
GROUP BY "Contractor".id;
Рисунок 49 – Поставки от заданного поставщика