-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZepto SQL Project.sql
More file actions
136 lines (112 loc) · 3.43 KB
/
Zepto SQL Project.sql
File metadata and controls
136 lines (112 loc) · 3.43 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
--This project is done in MS SQL.
create database Zepto_SQL_Project
use Zepto_SQL_Project
drop table if exists zepto
create table zepto(
sku_id int identity(1,1) primary key,
category varchar(120),
name varchar(150) not null,
mrp decimal(8,2),
discountPercent decimal(5,2),
availableQuantity integer,
discountedSellingPrice decimal(8,2),
weightInGms integer,
outOfStock bit,
quantity integer
)
--inserting data from csv to zepto
insert into zepto (category,name,mrp,discountPercent,availableQuantity,discountedSellingPrice,weightInGms,outOfStock,quantity)
select category,name,mrp,discountPercent,availableQuantity,discountedSellingPrice,weightInGms,outOfStock,quantity
from dbo.zepto_v2
--data exploration
--count of rows
select count(*) from zepto
--sample data
select top 10 * from zepto
--null values
select * from zepto
where name is null
or
name is null
or
category is null
or
mrp is null
or
discountPercent is null
or
discountedSellingPrice is null
or
weightInGms is null
or
availableQuantity is null
or
outOfStock is null
or
quantity is null
--different product categories
select distinct category from zepto
order by category
--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) as "Number of SKU's"
from zepto
group by name
having count(sku_id) > 1
order by count(sku_id) desc
--data cleaning
--products with price - zero
select * from zepto
where mrp=0 or discountedSellingPrice=0
delete from zepto
where mrp = 0 --1row effected
--convert paise to ruppes
update zepto
set
mrp = mrp/100.0,
discountedSellingPrice = discountedSellingPrice/100.0
--checking
select mrp,discountedSellingPrice from zepto
--Q1.Find the top 10 best-value products based on the discount percentage.
select distinct top 10 name, mrp, discountPercent from zepto
order by discountPercent desc
--Q2.What are the Products with High MRP but Out Of Stock
select distinct name,mrp from zepto
where outOfStock = 1 and mrp > 300
order by mrp desc
--Q3.Caluculate 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, discountPercent desc
--Q5.Identify the top 5 categories offering the highest average discount percentage.
select top 5 category,
cast(round(avg(discountPercent), 2) as decimal(10,2)) as avg_discount
from zepto
group by category
order by avg_discount desc
--Q6.Find the price per gram for products above 100g and sort by best value.
select distinct name, weightInGms, discountedSellingPrice,
cast(round(discountedSellingPrice/weightInGms,2) as decimal(10,2)) as price_per_gram
from zepto
where weightInGms>=100
order by price_per_gram
--Q7.Group the products into categories 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 the Total Inventory Weight Per Category
select category,
sum(weightInGms * availableQuantity) as total_weight
from zepto
group by category
order by total_weight