-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBikeStoreScript.sql
52 lines (45 loc) · 1.19 KB
/
BikeStoreScript.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
-- New script in master.
-- Date: Dec 10, 2022
-- Time: 8:16:31 PM
SELECT
ords.order_id ,
CONCAT(cus.first_name, ' ', cus.last_name) AS 'Customers',
cus.city ,
cus.state ,
ords.order_date,
SUM(oi.quantity) AS 'total_unit',
SUM(oi.quantity * oi.list_price) AS 'revenue',
pro.product_name,
cats.category_name,
stores.store_name,
CONCAT(staffs.first_name, ' ', staffs.last_name) AS 'Staffs'
FROM
BikeStores.sales.orders ords
JOIN BikeStores.sales.customers cus
ON
ords.customer_id = cus.customer_id
JOIN BikeStores.sales.order_items oi
ON
ords.order_id = oi.order_id
JOIN BikeStores.production.products pro
ON
oi.product_id = pro.product_id
JOIN BikeStores.production.categories cats
ON
pro.category_id = cats.category_id
JOIN BikeStores.sales.stores stores
ON
ords.store_id = stores.store_id
JOIN BikeStores.sales.staffs staffs
ON
staffs.store_id = stores.store_id
GROUP BY
ords.order_id ,
CONCAT(cus.first_name, ' ', cus.last_name),
cus.city ,
cus.state ,
ords.order_date,
pro.product_name,
cats.category_name,
stores.store_name,
CONCAT(staffs.first_name, ' ', staffs.last_name)