-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZepto.inventory_sql.sql
More file actions
143 lines (78 loc) · 3.09 KB
/
Zepto.inventory_sql.sql
File metadata and controls
143 lines (78 loc) · 3.09 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
143
drop table if exists Zepto;
create table Zepto(SKU_id SERIAL PRIMARY KEY,
category VARCHAR (150), name VARCHAR (150) not null,
mrp NUMERIC (8,2), discountpercent NUMERIC (5,2), availablequantity INTEGER,
discountedsellingPrice NUMERIC (10,2),
weightingms INTEGER, outofstock BOOLEAN,
quantity INTEGER);
-- data exploration
--count of rows
SELECT COUNT (*) FROM zepto;
-- sample data
SELECT * FROM zepto LIMIT 100;
-- null values
SELECT * FROM zepto WHERE
name IS NULL OR
category IS NULL OR
mrp IS NULL OR
discountpercent IS NULL OR
availablequantity IS NULL OR
discountedsellingprice IS NULL OR
weightingms IS NULL OR
outofstock IS NULL OR
quantity IS NULL;
-- different product categories
SELECT distinct category from zepto
ORDER BY category;
SELECT DISTINCT name from zepto
order by name;
-- products in stock vs out of stock
SELECT outofstock, COUNT(sku_id) FROM
zepto GROUP BY outofstock;
-- product names present multiple times
SELECT name , COUNT (sku_id) FROM zepto
GROUP BY name HAVING COUNT (sku_id)> 1 ORDER BY count (sku_id) desc;
-- data cleaning
-- product with price 0
select * from zepto where mrp = 0 or
discountedsellingprice=0;
delete from zepto where mrp = 0;
-- convert paise into rupees
update zepto
set mrp = mrp/100.0 , discountedsellingprice = discountedsellingprice/100.0;
select mrp, discountedsellingprice from zepto;
Q1: Find the top 15 best value products based on the discount percentage?
select distinct name,mrp,discountpercent from zepto
order by discountpercent desc limit 15;
Q2: What are the products with high mrp but out of stock?
select distinct name,mrp,outofstock from zepto
where outofstock = 'true' and mrp > 300 order by mrp desc;
Q3: calculate estimated revenue for each category?
select category, sum(discountedsellingprice*availablequantity)
as total_revenue from zepto group by category
order by total_revenue;
Q4:find all products where mrp is greater than 500 and discount is less than 10?
select distinct name,mrp,discountpercent from
zepto where mrp >500 and
discountpercent <10 order by mrp desc;
Q5:identify the top 5 categories offering the highest average discount percentage?
select category, round(avg(discountpercent),2) as
average_discount from zepto group by category
order by average_discount desc limit 5;
Q6:find price per gram for products above 100g and sort by best value?
select distinct name,weightingms, discountedsellingprice,
round(discountedsellingprice/weightingms,2)
as price_pergm from zepto where weightingms >= 100
order by price_pergm ;
Q7: group the products into category like low, medium, bulk
select distinct name, weightingms,
case when weightingms <1000 then 'low'
when weightingms <5000 then 'medium'
else 'bulk'
end as weight_category
from zepto;
Q8: what is total inventory weight per category?
select category, sum(weightingms * availablequantity)
as total_weight from zepto
group by category
order by total_weight desc;