-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-5.sql
More file actions
40 lines (36 loc) · 842 Bytes
/
7-5.sql
File metadata and controls
40 lines (36 loc) · 842 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
39
40
-- identify large sales with IF
select
orderid,
saleamount,
if(saleamount > 5000, 1, 0) as LargeSale
from sales_all_years
limit 1000;
-- create sales size categories
select
orderid,
saleamount,
case
when saleamount > 5000 then 'large'
when saleamount > 1000 then 'medium'
else 'small'
end as SalesSize
from sales_all_years
limit 1000;
-- perform what-if analysis by reassigning regions
select
case lower(region)
when 'west' then 'Southwest'
when 'south' then 'Southwest'
else region
end as new_region,
year(orderdate) as y,
sum(saleamount) as TotalSales
from sales_all_years
group by
case lower(region)
when 'west' then 'Southwest'
when 'south' then 'Southwest'
else region
end,
year(orderdate)
limit 100;