-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest 4.sql
More file actions
27 lines (26 loc) · 797 Bytes
/
Request 4.sql
File metadata and controls
27 lines (26 loc) · 797 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
/*4. Follow-up: Which segment had the most increase in unique products in
2021 vs 2020? The final output contains these fields,
segment
product_count_2020
product_count_2021
difference*/
with cte as
(select segment,count(distinct s.product_code) as product_count_2020
from fact_sales_monthly s
join dim_product p
on s.product_code=p.product_code
where fiscal_year=2020
group by segment),
cte2 as
(select segment,count(distinct s.product_code) as product_count_2021
from fact_sales_monthly s
join dim_product p
on s.product_code=p.product_code
where fiscal_year=2021
group by segment)
select cte.segment,product_count_2020,
product_count_2021,
(product_count_2021-product_count_2020) as difference
from cte
join cte2
where cte.segment=cte2.segment;