-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_Business_Analysis.SQL
More file actions
96 lines (75 loc) · 2.21 KB
/
4_Business_Analysis.SQL
File metadata and controls
96 lines (75 loc) · 2.21 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
------------------------------------------------Business Analysis-------------------------------------------
USE [Swiggy Database]
-- 1. Which cities consistently outperform and deserve expansion budget?
SELECT
l.city,
SUM(f.price_INR) AS total_revenue,
COUNT(DISTINCT d.[month]) AS active_months,
SUM(f.price_INR) * 1.0 / COUNT(DISTINCT f.order_ID) AS avg_order_value
FROM dbo.Fact_Order f
JOIN dbo.Dim_Location l
ON f.location_ID = l.location_ID
JOIN dbo.Dim_Date d
ON f.date_ID = d.date_ID
GROUP BY l.city
HAVING COUNT(DISTINCT d.[month]) >= 6
ORDER BY total_revenue DESC;
-- 2. Are we over-dependent on a few restaurants?
SELECT
r.restaurent_name,
SUM(f.price_INR) AS restaurant_revenue,
ROUND(
SUM(f.price_INR) * 100.0 /
SUM(SUM(f.price_INR)) OVER (), 2
) AS revenue_contribution_pct
FROM dbo.Fact_Order f
JOIN dbo.Dim_Restaurant r
ON f.restaurent_ID = r.restaurant_ID
GROUP BY r.restaurent_name
ORDER BY revenue_contribution_pct DESC;
-- 3. Which dishes are overpriced for demand?
SELECT
d.dish_name,
AVG(f.price_INR) AS avg_price,
COUNT(DISTINCT f.order_ID) AS total_orders
FROM dbo.Fact_Order f
JOIN dbo.Dim_Dish d
ON f.dish_ID = d.dish_ID
GROUP BY d.dish_name
HAVING COUNT(DISTINCT f.order_ID) <
(
SELECT AVG(order_cnt)
FROM (
SELECT COUNT(DISTINCT order_ID) AS order_cnt
FROM dbo.Fact_Order
GROUP BY dish_ID
) x
)
ORDER BY avg_price DESC;
-- 4. When should operations scale up or down?
SELECT
d.[year],
d.[month],
COUNT(DISTINCT f.order_ID) AS total_orders,
SUM(f.price_INR) AS total_revenue
FROM dbo.Fact_Order f
JOIN dbo.Dim_Date d
ON f.date_ID = d.date_ID
GROUP BY d.[year], d.[month]
ORDER BY d.[year], d.[month];
-- 5. Weekend vs Weekday Behavior
SELECT
CASE
WHEN d.day IN (6,7) THEN 'Weekend'
ELSE 'Weekday'
END AS day_type,
COUNT(DISTINCT f.order_ID) AS total_orders,
SUM(f.price_INR) * 1.0 / COUNT(DISTINCT f.order_ID) AS avg_order_value
FROM dbo.Fact_Order f
JOIN dbo.Dim_Date d
ON f.date_ID = d.date_ID
GROUP BY
CASE
WHEN d.day IN (6,7) THEN 'Weekend'
ELSE 'Weekday'
END;