-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBike_Store_Analysis.sql
More file actions
46 lines (42 loc) · 1.18 KB
/
Bike_Store_Analysis.sql
File metadata and controls
46 lines (42 loc) · 1.18 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
-- ============================================
-- Project : BikeStores Sales Analysis
-- Author : Your Name
-- Date : 2024
-- Purpose : Extracts order-level data for
-- Excel dashboard reporting
-- ============================================
use BikeStores
select
o.order_id,
concat(c.first_name, ' ', c.last_name) as full_name,
c.city,
c.state,
o.order_date,
sum(i.quantity) as total_units,
sum(i.quantity * i.list_price * (1 - i.discount)) as revenue,
p.product_name,
cat.category_name,
s.store_name,
concat(sta.first_name, ' ',sta.last_name) as sales_rep
from sales.orders o
join sales.customers c
on o.customer_id = c.customer_id
join sales.order_items i
on o.order_id = i.order_id
join production.products p
on p.product_id = i.product_id
join production.categories cat
on p.category_id = cat.category_id
join sales.stores s
on o.store_id = s.store_id
join sales.staffs sta
on sta.staff_id = o.staff_id
group by o.order_id,
concat(c.first_name, ' ', c.last_name),
c.city,
c.state,
o.order_date,
p.product_name,
cat.category_name,
s.store_name,
concat(sta.first_name, ' ',sta.last_name)