-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvance Analysis.sql
More file actions
75 lines (58 loc) · 1.8 KB
/
Copy pathAdvance Analysis.sql
File metadata and controls
75 lines (58 loc) · 1.8 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
--CUSTOMER VALUE INDEX
SELECT name, category,
ROUND((discountPercent / 100.0) * (weightInGms / discountedSellingPrice),4) AS value_index
FROM zepto
WHERE discountedSellingPrice > 0
ORDER BY value_index DESC
LIMIT 10;
--CATEGORY PERFORMANCE SCORE
SELECT category,
SUM(discountedSellingPrice * availableQuantity) AS revenue,
AVG(discountPercent) AS avg_discount,
COUNT(*) FILTER (WHERE availableQuantity < 20) AS high_demand,
COUNT(*) FILTER (WHERE availableQuantity > 100) AS overstock,
ROUND(
SUM(discountedSellingPrice * availableQuantity)
/ NULLIF(COUNT(*),0),2
) AS efficiency_score
FROM zepto
GROUP BY category
ORDER BY efficiency_score DESC;
--PRICE OPTIMIZATION
SELECT name, category,
discountedSellingPrice,
CASE
WHEN availableQuantity < 20 THEN discountedSellingPrice * 1.10
WHEN availableQuantity > 100 THEN discountedSellingPrice * 0.90
ELSE discountedSellingPrice
END AS suggested_price
FROM zepto;
--INVENTORY TURNOVER
SELECT category,
SUM(availableQuantity) AS total_stock,
COUNT(*) FILTER (WHERE availableQuantity < 20) AS fast_moving,
ROUND(
COUNT(*) FILTER (WHERE availableQuantity < 20) * 100.0 / COUNT(*),2
) AS turnover_rate
FROM zepto
GROUP BY category
ORDER BY turnover_rate DESC;
--PRICE DETECTION
SELECT name, category, mrp, discountedSellingPrice
FROM zepto
WHERE discountedSellingPrice > mrp;
--DUPLICATE PRODUCT PRICE
SELECT name,
MIN(discountedSellingPrice) AS min_price,
MAX(discountedSellingPrice) AS max_price,
(MAX(discountedSellingPrice) - MIN(discountedSellingPrice)) AS price_diff
FROM zepto
GROUP BY name
HAVING COUNT(*) > 1
ORDER BY price_diff DESC;
--INVENTORY COST
SELECT category,
SUM(mrp * availableQuantity) AS inventory_cost
FROM zepto
GROUP BY category
ORDER BY inventory_cost DESC;