-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL_Northwind_Exercises.sql
55 lines (37 loc) · 1.42 KB
/
SQL_Northwind_Exercises.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Weekend Exercises
- https://www.w3resource.com/mysql-exercises/northwind/products-table-exercises/
*/
USE Northwind
-- 1. Write a query to get a Product Name and quantity/Unit
SELECT p.ProductName, p.QuantityPerUnit
FROM Products p
-- 2. Write a query to get current product list (product ID and Name)
SELECT p.ProductID, p.ProductName
FROM Products p
-- 3. Write a query to get Product list (id, name, unit price) where products cost between $15 and $25
SELECT p.ProductID, p.ProductName, p.UnitPrice
FROM Products p
WHERE p.UnitPrice BETWEEN 15 AND 25
ORDER BY p.UnitPrice DESC
-- 4. Write a query to get Product list (name, unit price) of above average price.
SELECT DISTINCT p.ProductName, p.UnitPrice
FROM Products p
WHERE UnitPrice > (SELECT AVG(UnitPrice) FROM Products)
ORDER BY UnitPrice
-- 5. Write a query to get Product list (name, unit price) of ten most expensive products.
SELECT TOP 20 p.ProductName, p.UnitPrice
FROM Products p
ORDER BY p.UnitPrice DESC
-- 6. Write a query to show discontinued and continued items in a COUNT
SELECT COUNT(p.ProductID) AS "Products"
FROM Products p
GROUP BY p.Discontinued
SELECT * FROM [Order Details]
WHERE [Order Details].Quantity > 100
-- List products with order quantities greater than 100.
SELECT p.ProductName
FROM Products p
WHERE p.ProductID IN (SELECT od.ProductId
FROM [Order Details] od
WHERE od.Quantity > 100)
--