-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-1.sql
More file actions
38 lines (34 loc) · 969 Bytes
/
4-1.sql
File metadata and controls
38 lines (34 loc) · 969 Bytes
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
--Let's understand monthly sales figures
select
ordermonthyear as OrderMonth,
count(1) as OrderCount, --if every row represents one order we just count 1
sum(s.saleamount) as TotalSales,
avg(s.saleamount) as AvgSales,
min(s.saleamount) as MinSales,
max(s.saleamount) as MaxSales
from
sales_all_years s
where
lower(ordermonthyear) != 'ordermonthyear'
group by
ordermonthyear
order by
ordermonthyear desc
-- Now let's break it down further by category by month
select
ordermonthyear as OrderMonth,
productcategory as Category,
count(1) as OrderCount, --if every row represents one order we just count 1
sum(s.saleamount) as TotalSales,
avg(s.saleamount) as AvgSales,
min(s.saleamount) as MinSales,
max(s.saleamount) as MaxSales
from
sales_all_years s
where
lower(ordermonthyear) != 'ordermonthyear'
group by
ordermonthyear,
productcategory
order by
ordermonthyear desc