-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASSINGMENT02.sql
More file actions
127 lines (105 loc) · 2.33 KB
/
Copy pathASSINGMENT02.sql
File metadata and controls
127 lines (105 loc) · 2.33 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
-- FIRST Q: A
select
p.product_name,
p.list_price,
c.category_name
from
production.products p
inner join
production.categories c
on p.category_id = c.category_id
-- 2 question
select
c.first_name + ' ' + last_name AS full_name,
o.order_id,
o.order_date
from
sales.customers c
INNER JOIN
sales.orders o
on c.customer_id = o.customer_id;
-- 3 QUESTION
SELECT
p.product_name,
p.list_price,
c.category_name,
b.brand_name
FROM production.products p
INNER JOIN production.categories c
ON p.category_id = c.category_id
INNER JOIN production.brands b
ON p.brand_id = b.brand_id
ORDER BY
b.brand_name ASC,
p.product_name ASC;
4 QUESTION;
select
p.product_name,
oi.order_id,
oi.item_id
FROM
production.products p
LEFT JOIN
sales.order_items oi
ON p.product_id = oi.product_id
ORDER BY
oi.order_id ASC;
5:QUESTION ;
select
p.product_id,
p.product_name
FROM production.products p
LEFT JOIN sales.order_items oi
ON p.product_id = oi.product_id
WHERE oi.product_id IS NULL;
6: QUESTION
\
SELECT
s.store_name,
s.store_id,
o.order_id,
o.order_date
FROM sales.stores s
LEFT JOIN sales.orders o
ON s.store_id = o.store_id;
7 :QUESTION
--select
-- find first and lastname as fullname to the sales_id
select
s.first_name + ' ' + s.last_name AS staff_name,
m.first_name + ' ' + m.last_name AS manager_name
FROM sales.staffs s
INNER JOIN sales.staffs m
ON s.manager_id = m.staff_id;
8: QUESTION
SELECT
s.store_name,
b.brand_name
FROM sales.stores s
CROSS JOIN production.brands b;
-- Expected rows = (Number of Stores) × (Number of Brands)
-- In the BikeStores sample database:
-- 3 Stores × 9 Brands = 27 rows
9: QUESTION
--SELECT
-- O.ORDER_ID
-- P.PRODUCT_NAME
-- FROM sales.customers c
--INNER JOIN sales.orders o
SELECT
CONCAT(c.first_name, ' ', c.last_name) AS full_name,
o.order_id,
o.order_date,
p.product_name,
p.list_price
FROM sales.customers c
INNER JOIN sales.orders o
ON c.customer_id = o.customer_id
INNER JOIN sales.order_items oi
ON o.order_id = oi.order_id
INNER JOIN production.products p
ON oi.product_id = p.product_id
ORDER BY
o.order_date ASC,
full_name ASC;
-- ASWERS COMPLETES;;