Курсовая работа: База данных "фруктовый сад"
SELECT clients. clientName AS [Покупатели, не совершавшие покупки]
FROM clients
WHERE ID_client NOT IN (SELECT DISTINCT ID_client FROM Selling)
ORDER BY clientName;
Запрос на отчет по покупкам:
SELECT dilers. dilerName AS Поставщик, products. name AS Товар, buying. quantity AS [Количество товара], buying. sum*buying. quantity AS [Сумма сделки], buying. date AS [Дата сделки]
FROM (buying INNER JOIN dilers ON buying. ID_diler=dilers. ID_diler) INNER JOIN products ON buying. ID_product=products. ID_product;
Запрос на отчет по продажам:
SELECT clients. clientName AS Клиент, products. name AS Товар, selling. quantity AS [Количество товара], selling. sum*selling. quantity AS [Сумма сделки], selling. date AS [Дата сделки]
FROM ( (selling INNER JOIN clients ON selling. ID_client=clients. ID_client) INNER JOIN shelfs ON shelfs. ID_shelf=selling. ID_shelf) INNER JOIN products ON shelfs. ID_product=products. ID_product;
Запрос на поставщиков и закупки:
SELECT dilers. dilerName AS Поставщик, COUNT (ID_buying) AS [Количество сделок], SUM (buying. quantity*buying. sum) AS [Сумма всех сделок]
FROM dilers INNER JOIN buying ON dilers. ID_diler=buying. ID_diler
GROUP BY dilers. ID_diler, dilers. dilerName;
Запрос на поставщиков без поставок:
SELECT dilers. dilerName AS [Поставщики, не совершавшие поставок]
FROM dilers
WHERE ID_diler NOT IN (SELECT DISTINCT ID_diler FROM buying)
ORDER BY dilerName;
Запрос на продажи с клиентами:
SELECT clients. clientName AS Покупатель, COUNT (ID_selling) AS [Количество сделок], SUM (selling. quantity*selling. sum) AS [Сумма всех сделок]
FROM clients INNER JOIN selling ON clients. ID_client=selling. ID_client
GROUP BY clients. ID_client, clients. clientName;
Запрос на стоимость товаров на складе:
SELECT SUM (price*quantity) AS [Стоимость всех товаров на складе]
FROM shelfs;
Запрос на вставку обновлений продажи:
INSERT INTO selling (ID_client, ID_shelf, quantity, [sum])
SELECT ID_client, (SELECT ID_shelf FROM shelfs WHERE ID_shelf= (SELECT MAX (ID_shelf) FROM shelfs)), quantity, sum