Created
January 21, 2024 14:57
-
-
Save SlavikArt/3bd6920356885ada30b42498417cd98c to your computer and use it in GitHub Desktop.
Inner Join Querries (on Product)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 1. Показать названия и категории товаров, | |
-- поставщиками которых являются ООО "Паньки" | |
-- или ООО «Какие люди» | |
SELECT | |
Product.name AS 'product', | |
Category.name AS 'category', | |
Supplier.name AS 'supplier' | |
FROM Product | |
JOIN Category ON Category.id = Product.id_category | |
JOIN Delivery ON Product.id = Delivery.id_product | |
JOIN Supplier ON Supplier.id = Delivery.id_supplier | |
WHERE | |
Supplier.name IN ('OOO Panki', 'OOO Kakie Ludi') | |
-- 2. Выбрать все товары с указанием их поставщика, | |
-- имя производителя которых не содержит букв [АКМ], | |
-- и категория которых не "Крупы" | |
SELECT | |
Product.name AS 'product', | |
Category.name AS 'category', | |
Supplier.name AS 'supplier', | |
Producer.name AS 'producer' | |
FROM Product | |
JOIN Delivery ON Product.id = Delivery.id_product | |
JOIN Supplier ON Supplier.id = Delivery.id_supplier | |
JOIN Producer ON Producer.id = Product.id_producer | |
JOIN Category ON Category.id = Product.id_category | |
WHERE | |
Producer.name NOT LIKE '%[AKM]%' | |
AND Category.name <> 'Grains' | |
-- 3. Показать названия и категории товаров | |
-- с указанием поставщика и страны производителя. | |
-- Условие: страна производителя не Украина и не Польша, | |
-- цена поставки менее 50 гривен, | |
-- а дата поставки от 10.10.2023 и по сей день | |
SELECT | |
Product.name AS 'product', | |
Category.name AS 'category', | |
Supplier.name AS 'supplier' , | |
Delivery.price AS 'delivery_price', | |
Country.name AS 'country_of_producer' | |
FROM Product | |
JOIN Category ON Category.id = Product.id_category | |
JOIN Delivery ON Product.id = Delivery.id_product | |
JOIN Supplier ON Supplier.id = Delivery.id_supplier | |
JOIN Producer ON Producer.id = Product.id_producer | |
JOIN Address ON Address.id = Producer.id_address | |
JOIN City ON City.id = Address.id_city | |
JOIN Region ON Region.id = City.id_region | |
JOIN Country ON Country.id = Region.id_country | |
WHERE | |
Country.name NOT IN ('Ukraine', 'Poland') | |
AND Delivery.price < 50 | |
AND Delivery.date_of_delivery BETWEEN '2023-10-10' AND GETDATE() | |
-- 4. Показать все кондитерские и безалкогольные товары, | |
-- которых было продано более 100. | |
-- Показать информацию о поставщике и производителе | |
SELECT | |
Product.name AS 'product', | |
Category.name AS 'category', | |
Sale.quantity AS 'sold_quantity', | |
Supplier.name AS 'supplier', | |
Producer.name AS 'producer' | |
FROM Product | |
JOIN Category ON Category.id = Product.id_category | |
JOIN Sale ON Product.id = Sale.id_product | |
JOIN Delivery ON Product.id = Delivery.id_product | |
JOIN Supplier ON Supplier.id = Delivery.id_supplier | |
JOIN Producer ON Producer.id = Product.id_producer | |
WHERE | |
Category.name IN ('Sweets', 'Alcohol') | |
AND Sale.quantity > 100 | |
-- 5. Сделать запрос на выборку информации о поставке товаров | |
-- в следующем виде: название товара и его поставщика, | |
-- категории, дата поставки и общую стоимость поставленных товаров. | |
-- Условие: только трёх указанных в запросе поставщиков. | |
-- Отсортировать названия товаров в алфавитном порядке | |
SELECT | |
Product.name AS 'product', | |
Supplier.name AS 'supplier', | |
Category.name AS 'category', | |
Delivery.date_of_delivery, | |
Delivery.price AS 'delivery_price' | |
FROM Product | |
JOIN Delivery ON Product.id = Delivery.id_product | |
JOIN Supplier ON Supplier.id = Delivery.id_supplier | |
JOIN Category ON Category.id = Product.id_category | |
WHERE | |
Supplier.name IN ('Amazon', 'Rozetka', 'eBay') | |
ORDER BY Product.name | |
-- 6. Сделать запрос на выборку о продажах товаров | |
-- в следующем виде: название товара и его производителя, | |
-- полный адрес (страна, город, улица) производителя в одной ячейке, | |
-- категории, дата продажи и общая стоимость продажи. | |
-- Условие: выведенная информация не должна касаться | |
-- двух указанных в запросе производителей. | |
-- Отсортировать общую стоимость продаж в порядке убывания | |
SELECT | |
Product.name AS 'product', | |
Producer.name AS 'producer', | |
(Country.name + ', ' + City.name + ', ' + Address.street) AS 'producer_address', | |
Category.name AS 'category', | |
Sale.date_of_sale, | |
Sale.price AS 'sell_price' | |
FROM Product | |
JOIN Producer ON Producer.id = Product.id_producer | |
JOIN Address ON Address.id = Producer.id_address | |
JOIN City ON City.id = Address.id_city | |
JOIN Region ON Region.id = City.id_region | |
JOIN Country ON Country.id = Region.id_country | |
JOIN Category ON Category.id = Product.id_category | |
JOIN Sale ON Product.id = Sale.id_product | |
WHERE | |
Producer.name NOT IN ('Philips', 'Panasonic') | |
ORDER BY Sale.price DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment