-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPizza sales analysis.sql
More file actions
114 lines (71 loc) · 3.18 KB
/
Pizza sales analysis.sql
File metadata and controls
114 lines (71 loc) · 3.18 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
CREATE DATABASE PIZZAHUT;
use PIZZAHUT;
select * from order_details
select * from orders
select * from pizza_types
select * from pizzas
------Retrieve the total number of orders placed.
select count(order_id) as total_orders from orders
-------Calculate the total revenue generated from pizza sales.
select SUM(order_details.quantity*pizzas.price) as total_revenue from order_details
inner join pizzas
on order_details.pizza_id= pizzas.pizza_id
-------Identify the highest-priced pizza.
select top 1 pizza_types.name,pizzas.price
from pizza_types inner join pizzas
on pizza_types.pizza_type_id= pizzas.pizza_type_id
order by pizzas.price desc
-------Identify the most common pizza size ordered.
select count(order_details.order_details_id) tot_qty, pizzas.size
from order_details inner join pizzas
on order_details.pizza_id=pizzas.pizza_id
group by pizzas.size
order by tot_qty desc
--------Join the necessary tables to find the total quantity of each pizza category ordered.
select pizza_types.category, sum(order_details.quantity) as tot_qty
from pizza_types inner join pizzas
on pizza_types.pizza_type_id=pizzas.pizza_type_id
inner join order_details
on order_details.pizza_id=pizzas.pizza_id
group by pizza_types.category
order by tot_qty desc
--------Determine the distribution of orders by hour of the day.
select DATEPART(hour,time) , COUNT(order_id) as tot_or from orders
group by DATEPART(hour,time)
order by tot_or desc;
-------Join relevant tables to find the category-wise distribution of pizzas.
select category,COUNT(name) from pizza_types
group by category
------Group the orders by date and calculate the average number of pizzas ordered per day.
select avg (tot_or) from
(select orders.date , SUM(order_details.quantity) as tot_or
from orders inner join order_details
on orders.order_id=order_details.order_id
group by orders.date) as a
-------Determine the top 3 most ordered pizza types based on revenue.
select top 3 pizza_types.name,SUM(order_details.quantity*pizzas.price) as revenue
from pizza_types inner join pizzas
on pizza_types.pizza_type_id=pizzas.pizza_type_id
inner join order_details on
order_details.pizza_id=pizzas.pizza_id
group by pizza_types.name
order by revenue desc
--------Calculate the percentage contribution of each pizza type to total revenue.
select pizza_types.category,
(SUM(order_details.quantity*pizzas.price) /( select SUM(order_details.quantity*pizzas.price) from
order_details inner join pizzas
on order_details.pizza_id=pizzas.pizza_id)* 100) as revenue from
pizza_types inner join pizzas
on pizza_types.pizza_type_id=pizzas.pizza_type_id
inner join order_details
on order_details.pizza_id=pizzas.pizza_id
group by pizza_types.category
order by revenue desc
------Determine the top 3 most ordered pizza types based on revenue for each pizza category.
select top 3 pizza_types.category, SUM(order_details.quantity*pizzas.price) as revenue
from pizza_types inner join pizzas
on pizza_types.pizza_type_id=pizzas.pizza_type_id
inner join order_details
on order_details.pizza_id=pizzas.pizza_id
group by pizza_types.category
order by revenue desc