-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal Reatail Analysis.sql
More file actions
142 lines (103 loc) · 4.11 KB
/
Final Reatail Analysis.sql
File metadata and controls
142 lines (103 loc) · 4.11 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
create database retail_aanalysis_project
use retail_aanalysis_project
select top 6 * from login --(L) ------L.user_id = SO.fk_buyer_id ---------------6,66,375 rows
select top 6 * from sales_orders --(SO) -----SO.order_id = SI.fk_order_id ---------------13,630 rows
select top 6 * from sales_items --(SI) ------ SO.order_id = SI.fk_order_id ---------------20,488 rows
1. Make a dataset (Using SQL) named “daily_logins” which contains the number of logins on a daily basis
----also see daily trend of login
select distinct date,count(log_id) over (partition by date order by date) as daily_logins from
(select distinct login_log_id as log_id, convert(date,login_time) as date from login) as Sp order by date
2.daily trend of login and trend of conversion (no. order placed per login)
---no. of order placed per logins
select distinct convert(date,login_time)as date, login_log_id,COUNT(order_id) ORD_COUNT
from
(
select *
from login L FULL JOIN sales_orders SO
ON L.user_id=SO.fk_buyer_id
WHERE L.user_id=SO.fk_buyer_id
) as Sp
GROUP BY login_log_id,convert(date,login_time)
order by login_log_id
--3. Prepare a report regarding our growth between the 2 years. Please try to answer the
--following questions:
--a. Did our business grow?
---------year wise
select year(creation_time) year,count(distinct order_id) order_count,
sum(order_quantity_accepted*rate) total_revenue
from sales_items join sales_orders
on order_id=fk_order_id
where sales_order_status like 'shipped'
group by year(creation_time)
--b. Does our app perform better now?
--------YEAR WISE
with cte1 as
(
select year(creation_time) as order_year,count(order_id) shipped_order_count
from sales_orders
where sales_order_status like 'shipped'
group by year(creation_time)
),
cte2 as
(
select year(creation_time) as order_year,count(order_id) rejected_order_count
from sales_orders
where sales_order_status like 'rejected'
group by year(creation_time)
),
cte3 as
(
select year(login_time) login_year ,count(login_log_id) login_count,count(distinct user_id) user_id
from login
group by year(login_time)
)
select cte1.order_year,shipped_order_count,rejected_order_count,login_count ,user_id
from cte1 join cte2 on cte1.order_year=cte2.order_year
join cte3 on cte3.login_year=cte2.order_year
--c. Did our user base grow?
--------YEAR WISE
select year(login_time) year,count(distinct USER_ID) user_count from login group by year(login_time) order by year
--4. What are our top-selling products in each of the two years? Can you draw some insight
--from this?
select year, fk_product_id, acc_orders_qty from
(
select year(creation_time) as year, fk_product_id,
sum(order_quantity_accepted) as acc_orders_qty,
DENSE_RANK() over (partition by year(creation_time) order by sum(order_quantity_accepted)
desc) as rank
from sales_items join sales_orders on
fk_order_id= order_id
where order_quantity_accepted>0
group by year(creation_time), fk_product_id
) as sp
where rank = 1
--5. Looking at July 2021 data, what do you think is our biggest problem and how would you
--recommend fixing it?
select top 6 * from login
select top 6 * from sales_orders
select top 6 * from sales_items
show --- sum sales_ord_status / decline + login_count
with cte1 as
(
select year(creation_time) as order_year,count(order_id) shipped_order_count
from sales_orders
where sales_order_status like 'shipped' and year(creation_time)='2021'
group by year(creation_time)
),
cte2 as
(
select year(creation_time) as order_year,count(order_id) rejected_order_count
from sales_orders
where sales_order_status like 'rejected' and year(creation_time)='2021'
group by year(creation_time)
),
cte3 as
(
select year(login_time) login_year ,count(login_log_id) login_count
from login
where year(login_time)='2021'
group by year(login_time)
)
select cte1.order_year,shipped_order_count,rejected_order_count,login_count
from cte1 join cte2 on cte1.order_year=cte2.order_year
join cte3 on cte3.login_year=cte2.order_year