Resume Project challenge of providing insight on Consumer Goods Domain
request1:
Provide the list of markets in which customer "Atliq Exclusive" operates its business in the APAC region.
select distinct(market) from dim_customer
where customer = 'Atliq Exclusive'
and region = 'APAC
market | |
---|---|
0 | India |
1 | Indonesia |
2 | Japan |
3 | Philiphines |
4 | South Korea |
5 | Australia |
6 | Newzealand |
7 | Bangladesh |
request2:
What is the percentage of unique product increase in 2021 vs. 2020? The final output contains these fields,unique_products_2020 unique_products_2021 percentage_chg
with
Unique_Product_2020 as(
select count(distinct(product_code)) as unique_product_2020
from fact_sales_monthly
where fiscal_year = 2020),
Unique_Product_2021 as(
select count(distinct(product_code)) as unique_product_2021
from fact_sales_monthly
where fiscal_year = 2021),
Percentage_Change as(
select
round(((unique_product_2021-unique_product_2020)/unique_product_2020)*100)
as pct_change
from Unique_Product_2021,
Unique_Product_2020)
select * from Unique_Product_2020,
Unique_Product_2021,
Percentage_Change;
unique_product_2020 | unique_product_2021 | pct_change | |
---|---|---|---|
0 | 245 | 334 | 36.0 |
request 3:
Provide a report with all the unique product counts for each segment and sort them in descending order ofproduct counts. The final output contains 2 fields,segment product_count
select segment ,count(distinct(product_code)) as product_count
from dim_product
group by segment
order by product_count desc;select segment ,count(distinct(product_code)) as product_count
from dim_product
group by segment
order by product_count desc;
segment | product_count | |
---|---|---|
0 | Notebook | 129 |
1 | Accessories | 116 |
2 | Peripherals | 84 |
3 | Desktop | 32 |
4 | Storage | 27 |
5 | Networking | 9 |
request 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
Unique_Segment_Product_2020 as(
select t2.segment,
count(distinct(t1.product_code)) as unique_product_2020
from fact_sales_monthly t1 join dim_product t2
on t1.product_code = t2.product_code
where fiscal_year = 2020
group by t2.segment),
Unique_Segment_Product_2021 as(
select t2.segment,
count(distinct(t1.product_code)) as unique_product_2021
from fact_sales_monthly t1 join dim_product t2
on t1.product_code = t2.product_code
where fiscal_year = 2021
group by t2.segment)
select s1.segment , unique_product_2020 ,unique_product_2021,
unique_product_2021 - unique_product_2020
as difference
from Unique_Segment_Product_2020 s1 join
Unique_Segment_Product_2021 s2 on
s1.segment =s2.segment
order by difference desc;
segment | unique_product_2020 | unique_product_2021 | difference | |
---|---|---|---|---|
0 | Accessories | 69 | 103 | 34 |
1 | Notebook | 92 | 108 | 16 |
2 | Peripherals | 59 | 75 | 16 |
3 | Desktop | 7 | 22 | 15 |
4 | Storage | 12 | 17 | 5 |
5 | Networking | 6 | 9 | 3 |
request 5:
Get the products that have the highest and lowest manufacturing costs. The final output should contain these fields, product_code product manufacturing_cost
select f.product_code , product ,manufacturing_cost
from fact_manufacturing_cost f join dim_product p
on f.product_code = p.product_code
where f.manufacturing_cost in (
select max(manufacturing_cost) from fact_manufacturing_cost
union
select min(manufacturing_cost) from fact_manufacturing_cost)
order by manufacturing_cost desc;
product_code | product | manufacturing_cost | |
---|---|---|---|
0 | A6120110206 | AQ HOME Allin1 Gen 2 | 240.5364 |
1 | A2118150101 | AQ Master wired x1 Ms | 0.8920 |
request 6:
Generate a report which contains the top 5 customers who received an average high pre_invoice_discount_pct for the fiscal year 2021 and in the Indian market. The final output contains these fields, customer_code customer average_discount_percentage
select c.customer_code ,c.customer,
round(avg(d.pre_invoice_discount_pct),2) as avg_discount_pct
from dim_customer c join fact_pre_invoice_deductions d
on c.customer_code = d.customer_code
where market = 'India'
group by c.customer_code
order by avg_discount_pct desc limit 5;
customer_code | customer | avg_discount_pct | |
---|---|---|---|
0 | 90002009 | Flipkart | 0.30 |
1 | 90002003 | Ezone | 0.28 |
2 | 90002004 | Vijay Sales | 0.28 |
3 | 90002011 | Atliq Exclusive | 0.27 |
4 | 90002006 | Viveks | 0.27 |
request 7:
Get the complete report of the Gross sales amount forthe customer “Atliq Exclusive” for each month .This analysis helps to get an idea of low and high-performing months and take strategic decisions. The final report contains these columns:Month Year Gross sales Amount
select monthname(s.date) as month,
year(s.date) year,s.fiscal_year ,
round(sum(s.sold_quantity*g.gross_price)/1000000,2) as gross_amount
from dim_customer c join fact_sales_monthly s
on c.customer_code = s.customer_code join fact_gross_price g
on s.product_code = g.product_code
where c.customer = 'Atliq Exclusive'
group by year(s.date), monthname(s.date)
order by year(s.date) asc , month(s.date) asc;
month | year | fiscal_year | gross_amount | |
---|---|---|---|---|
0 | September | 2019 | 2020 | 9.09 |
1 | October | 2019 | 2020 | 10.38 |
2 | November | 2019 | 2020 | 15.23 |
3 | December | 2019 | 2020 | 9.76 |
4 | January | 2020 | 2020 | 9.58 |
5 | February | 2020 | 2020 | 8.08 |
6 | March | 2020 | 2020 | 0.77 |
7 | April | 2020 | 2020 | 0.80 |
8 | May | 2020 | 2020 | 1.59 |
9 | June | 2020 | 2020 | 3.43 |
10 | July | 2020 | 2020 | 5.15 |
11 | August | 2020 | 2020 | 5.64 |
12 | September | 2020 | 2021 | 19.53 |
13 | October | 2020 | 2021 | 21.02 |
14 | November | 2020 | 2021 | 32.25 |
15 | December | 2020 | 2021 | 20.41 |
16 | January | 2021 | 2021 | 19.57 |
17 | February | 2021 | 2021 | 15.99 |
18 | March | 2021 | 2021 | 19.15 |
19 | April | 2021 | 2021 | 11.48 |
20 | May | 2021 | 2021 | 19.20 |
21 | June | 2021 | 2021 | 15.46 |
22 | July | 2021 | 2021 | 19.04 |
23 | August | 2021 | 2021 | 11.32 |
request 8:
In which quarter of 2020, got the maximum total_sold_quantity?The final output contains these fields sorted by the total_sold_quantity,Quarter total_sold_quantity
with base_query as (
select *,date_add(date,interval 4 month) as formatted_date from fact_sales_monthly)
select year(formatted_date) as fiscal_year,
quarter(formatted_date) as quarter_ ,
sum(sold_quantity) as total_sold_quantity
from base_query group by year(formatted_date) , quarter(formatted_date);
fiscal_year | quarter_ | total_sold_quantity | |
---|---|---|---|
0 | 2020 | 1 | 7005619.0 |
1 | 2020 | 2 | 6649642.0 |
2 | 2020 | 3 | 2075087.0 |
3 | 2020 | 4 | 5042541.0 |
4 | 2021 | 1 | 14476194.0 |
5 | 2021 | 2 | 13812652.0 |
6 | 2021 | 3 | 10984739.0 |
7 | 2021 | 4 | 10890997.0 |
request 9:
Which channel helped to bring more gross sales in the fiscal year 2021 and the percentage of contribution? The final output contains these fields,channel gross_sales_mln percentage
with base_query as(
select s.fiscal_year,c.channel ,s.sold_quantity , g.gross_price ,
(s.sold_quantity*g.gross_price) as gross_amount
from fact_sales_monthly s join fact_gross_price g
on s.product_code = g.product_code join dim_customer c on
s.customer_code = c.customer_code where s.fiscal_year = 2021)
select channel,total_gross_amount,
round((total_gross_amount/sum(total_gross_amount) over())*100,2) as pct from
(select channel ,sum(gross_amount) as total_gross_amount from base_query
group by channel) t order by pct desc limit 1;
channel | total_gross_amount | pct | |
---|---|---|---|
0 | Retailer | 1.924170e+09 | 73.22 |
request 10:
Get the Top 3 products in each division that have a high total_sold_quantity in the fiscal_year 2021? The final output contains these fields,division product_code
with base_query as
(select s.fiscal_year,p.division,s.product_code,p.product,s.sold_quantity,
rank() over(partition by p.division order by sold_quantity desc ) as product_rank_division
from fact_sales_monthly s join dim_product p on s.product_code = p.product_code
where fiscal_year =2021 group by p.division ,p.product_code)
select * from base_query where product_rank_division < 4
fiscal_year | division | product_code | product | sold_quantity | product_rank_division | |
---|---|---|---|---|---|---|
0 | 2021 | N & S | A6818160202 | AQ Pen Drive DRC | 1331 | 1 |
1 | 2021 | N & S | A6319160202 | AQ Neuer SSD | 944 | 2 |
2 | 2021 | N & S | A6819160203 | AQ Pen Drive DRC | 940 | 3 |
3 | 2021 | P & A | A2319150302 | AQ Gamers Ms | 1038 | 1 |
4 | 2021 | P & A | A2721150704 | AQ Trigger Ms | 1034 | 2 |
5 | 2021 | P & A | A2520150501 | AQ Maxima Ms | 1000 | 3 |
6 | 2021 | PC | A4520110504 | AQ Gen X | 39 | 1 |
7 | 2021 | PC | A4218110207 | AQ Digit | 38 | 2 |
8 | 2021 | PC | A4218110205 | AQ Digit | 37 | 3 |