Pizza Sales Data Analysis using MySQL > Objective: Extract sales insights from pizza order dataset.. > Dataset: Orders, Order Details, Pizzas, Pizza Types > Tools: MySQL, Excel for
Trang 1Pizza Sales Data Analysis using
MySQL
> Objective: Extract sales insights from pizza order
dataset
> Dataset: Orders, Order Details, Pizzas, Pizza Types
> Tools: MySQL, Excel (for charts)
Trang 2Pizza Sales Database
' create database pizzahut;
+ CREATE TABLE orders ( [> Result
order_id INT NOT NULL,
order_date DATE NOT NULL,
order_time TIME NOT NULL,
| Result Grid | $Ề Filter Rows: | Edit:
T | order detals d order id pizza_id quantity
5 2 thai_ckn_| 1 |)
7 3 ital_supr_m 1
order_details_id INT NOT NULL, » E ital_supr_m :
order id INT NOT NULL, 11 6 bbq_ckn_s 1
pizza_id TEXT NOT NULL, 12 6 moe s 1
13 7 spinach_supr_s 1 quantity INT NOT NULL, 14 8 spinach sur s 1
PRIMARY KEY (order_details_id));
SELECT *FROM
order details;
Trang 3Q.1- Retrieve the total number of
orders placed
> Query
> Result SELECT
COUNT(order id) AS total orders | Result Grid | {Hh $% r
> 21550
orders |
Trang 4Q.2- Calculate the total revenue
generated from pizza sales
> Query
SELECT
ROUND(SUM(order_details.quantity * pizzas.price),
2) AS total_sales
order details
JOIN
pizzas ON pizzas.pizza_id = order_details.pizza_id
| Result Grid | fH $Ề% Filter
| total_sales
> 317860.05
Trang 5Q.3- Identify the highest-priced
pizza
> Query
pizza _types.name, pizzas.price
FROM
ORDER BY pizzas.price DESC > TheGreekPizza 35.95
LIMIT 1;
Trang 6Q.4- Identify the most common
pizza size ordered
> Query
SELECT
pizzas.size,
[> Result
COUNT (order_details.order_details_id) as order_count
FROM
order_details ON pizzas.pizza_id = order_details.pizza_id > 18525
xXxL 28
Trang 7Q.5- List the top 5 most ordered pizza
types along with their quantities
> Query
SELECT
pizza_types.name, SUM(order_details.quantity) AS quantity
FROM
pizza_types
JOIN
pizzas ON pizza_types.pizza_type_id = pizzas.pizza_type id > Result
JOIN
Result Grid | | Filter Rows:
name quantity
> |The Classic Deluxe Pizza 2453 The Barbeque Chicken Pizza 2432
The Pepperoni Pizza 2418 The Thai Chicken Pizza 2371
GROUP BY pizza_types.name
ORDER BY quantity DESC
Trang 8Q.6- Total quantity of each pizza
category ordered (Join tables)
> Query
SELECT
pizza_types.category,
SUM(order_details.quantity) AS quantity
FROM
JOIN
pizzas ON pizza _types.pizza type_id = pizzas.pizza_type id | Result Grid | TH @} Fite
Chicken 11050
Trang 9Q.7-Distribution of orders by hour
of the day
> Query
SELECT
HOUR(order_ time) AS hour, > Result
; | Result Grid | TH @) Filter Row
COUNT(order_id) AS order_count _ | hour order count
> 11 1251
13 2455
18 2399
19 2009
20 1642
21 1198
22 663
25 28
10 Ss
Trang 10Q.8- Category-wise distribution of
pizzas (Join tables)
> Query
SELECT
FROM
| Result Grid | {} @} Filter Rows:
Classic 8
Veggie 9
Trang 11Q.9- Group orders by date & calculate
avg pizzas per day
> Query
SELECT
round(AVG(quantity),@) avg _pizza_ordered_per day
orders.order date, SUM(order details.quantity) AS quantity | Result Grid | {4 > Filter Rows:
FROM avg_pizza_ordered_per day
.} 158 J01N order details ON orders.order_id = order_details.order_id
GROUP BY orders.order date) AS order quantity;
Trang 12Q.10-Top 3 most ordered pizza types
based on revenue
> Query
SELECT
pizza_types.name,
SUM(order_details.quantity * pizzas.price) AS revenue
FROM
pizza_types
JOIN pizzas ON pizzas.pizza_type_id = pizza_types.pizza_ type id
JOIN order_details ON order_details.pizza_id = pizzas.pizza_id
GROUP BY pizza_types.name
ORDER BY revenue DESC
LIMIT 3;
> Result
| Result Grid | HH] @) Fitter Rows:
'» |The Thai Chicken Pizza 4⁄43425
The Barbecue Chicken Pizza 42768 The California Chicken Pizza 41409.5
Trang 13Q.11- % contribution of each pizza
type to total revenue
> Query
SELECT
pizza_types.category,
ROUND(SUM(order_details.quantity * pizzas.price) / (SELECT
ROUND(SUM(order_details.quantity * pizzas.price),
2) AS total_sales [> Re sult
FROM
order_details
pizzas ON pizzas.pizza_id = order_details.pizza_id) * 100, [ ï
ran > Classic 26.91
pizza_types
pizzas ON pizza_types.pizza_type id = pizzas.pizza_type id Chicken 23.96
on order_details.pizza_id = pizzas.pizza_id
group by pizza_types.category order by revenue desc;
Trang 14Q.12- Analyze the cumulative revenue
generated over time
> Query
select order date,
sum(revenue) over (order by order date) as cum revenue
from
(select orders.order date,
sum(order_details.quantity * pizzas.price) as revenue
from order details join pizzas
on order details.pizza id = pizzas.pizza_ id
join orders
on orders.order id = order details.order id
group by orders.order date) as sales;
> Result
| Result Grid | đR + Filter Rows:
>
order_date
2015-01-01
2015-01-02
2015-01-03 2015-01-04 2015-01-05
2015-01-06
2015-01-07 2015-01-08 2015-01-09
2015-01-10
2015-01-11 2015-01-12 2015-01-13 2015-01-14
Cum_revenue
2713.8500000000004 5445.75
8108.15 9863.6 11929.55 14358.5 16560.7 19399.05 21526.4 23990.350000000002 25862.65
27781.7 29831.300000000003
32358 700000000004
Trang 15Q.13- Determine the top 3 most
ordered pizza types based on revenue
for each pizza category
> Query
Select name, revenue from
(select category,name,revenue, > Result
rank() over(partition by category order by revenue desc)as RN | ResultGrid | {9 @} Fitter Rows:
(select p1zza_types.category, p1zza_ types name, > Sr 43434.4
sum((order_details.quantity) * pizzas.price) as revenue The California Chicken Pizza 41409.5
on pizza _types.pizza type id = pizzas.pizza_ type id The Pepperoni Pizza 30161.75
The Italian Supreme Pizza 33476.75
on order details.pizza_id = pizzas.pizza_id The Sidkan Pizza 30940.5
group by pizza_types.category, pizza_types.name) as a)as b The Four Cheese Pizza 32265 70000000065
where RN <=3; The Five Cheese Pizza
26066 5
Trang 16vvvvy
Summary of key findings:
- Best-selling pizzas & sizes
- Peak sales times
- Revenue contribution per category
- Growth trends
Recommendations:
- Stock management
- Marketing offers
- Promotions during peak times