-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueries.sql
More file actions
74 lines (50 loc) · 2.21 KB
/
Queries.sql
File metadata and controls
74 lines (50 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
A. KPI
-- 1. Total Revenue
select SUM(total_price) as Total_Revenue from pizza_sales
-- 2. Average Order Value
select SUM(total_price)/ COUNT(distinct order_id) as Average_Total_Order from pizza_sales
-- 3. Total Pizzas Sold
select SUM(quantity) as Total_Pizza_Sold from pizza_sales
-- 4. Total Orders
select count(distinct order_id) as Total_Orders from pizza_sales
-- 5. Averages Pizza Per Order
select cast(cast(sum(quantity) as decimal(10,2))/
cast(count(distinct order_id) as decimal(10,2)) as decimal(10,2))
as Avg_Pizzas_Per_Orders from pizza_sales
-- B. Daily Trend for Total Orders:
SELECT DATENAME(DW, order_date) AS Order_Day,COUNT(DISTINCT order_id) AS Total_Orders
FROM pizza_sales
GROUP BY DATENAME(DW, order_date), DATEPART(DW, order_date)
ORDER BY DATEPART(DW, order_date) ASC;
-- C. Hourly Trend for Total Orders
select DATEPART(HOUR,order_time) as Orders_Hours, COUNT(distinct order_id) as Total_Orders
from pizza_sales
group by DATEPART(Hour,order_time)
order by DATEPART(Hour,order_time)
-- D. Percentage of Sales by Pizza Category
select pizza_category, SUM(total_price) as Total_Sales, sum(total_price)*100/
(select SUM(total_price) from pizza_sales) as Percentage_Sales_Categorywise
from pizza_sales
group by pizza_category
order by Percentage_Sales_Categorywise asc
-- E. Percentage of Sales by Pizza Size
select pizza_size, round(SUM(total_price),2) as Total_Sales, round(sum(total_price)*100/
(select SUM(total_price) from pizza_sales),2) as Percentage_Sales_Categorywise
from pizza_sales
group by pizza_size
order by Percentage_Sales_Categorywise asc
-- F. Total Pizzas sold by Pizza Category
select pizza_category, SUM(quantity) as Total_Sold
from pizza_sales
group by pizza_category
order by Total_Sold
-- G. Top 5 Best Sellers by Total Pizzas Sold
select top 5 pizza_name, SUM(quantity) as Total_Pizza_Sold
from pizza_sales
group by pizza_name
order by Total_Pizza_Sold desc
-- A. Bottom 5 Worst Sellers by Total Pizzas Sold
select top 5 pizza_name, SUM(quantity) as Total_Pizza_Sold
from pizza_sales
group by pizza_name
order by Total_Pizza_Sold