This project is focused on SQL practice using PizzaHut sales data in MySQL Workbench. It includes schema modifications, indexing, and advanced analytics queries to extract business insights.
The dataset consists of orders, pizza details, pizza types, and sales transactions. This analysis helps understand ordering patterns, revenue trends, and pizza preferences.
Field | Type | Description |
---|---|---|
order_id | INT | Unique order identifier |
date | DATE | Order date |
time | TIME | Order time |
order_year | INT | Extracted year from date |
order_month | INT | Extracted month from date |
order_day | INT | Extracted day from date |
Field | Type | Description |
---|---|---|
order_details_id | INT | Unique order detail ID |
order_id | INT | Foreign key referencing orders |
pizza_id | TEXT | Foreign key referencing pizzas |
quantity | INT | Quantity of ordered pizzas |
Field | Type | Description |
---|---|---|
pizza_id | TEXT | Unique pizza identifier |
pizza_type_id | TEXT | Foreign key referencing pizza_types |
size | TEXT | Pizza size (Small, Medium, Large) |
price | DOUBLE | Pizza price |
Field | Type | Description |
---|---|---|
pizza_type_id | VARCHAR(50) | Unique pizza type identifier |
name | VARCHAR(255) | Name of the pizza |
category | VARCHAR(50) | Pizza category (Veg, Non-Veg, Special) |
ingredients | TEXT | Ingredients used |
- Retrieve the total number of distinct orders. ✅
- Find the number of orders placed on each date. ✅
- Get the total revenue from all pizza sales. ✅
- Identify the highest-priced pizza. ✅
- Find the most common pizza size ordered. ✅
- Retrieve the names of all unique pizza types available. ✅
- Count the number of orders placed per year. ✅
- Identify the top 5 most ordered pizza types by quantity. ✅
- List all pizzas along with their sizes and prices. ✅
- Find the pizza with the lowest price. ⏳ Pending
- Retrieve the names of pizzas containing "Cheese" in their ingredients. ⏳ Pending
- Count the total number of pizza orders for each day of the week. ⏳ Pending
- List all unique pizza categories available. ⏳ Pending
- Find the maximum quantity ordered for a single order. ⏳ Pending
- Count how many pizzas were ordered in the last 7 days. ⏳ Pending
- Identify the top 3 most expensive pizzas. ✅
- Identify the top 5 most ordered pizza types by quantity. ✅
- Determine the number of orders placed during each hour of the day. ✅
- Calculate the average order quantity per order. ✅
- Find the distribution of pizza categories across all orders. ✅
- Get the total number of pizzas ordered for each day. ✅
- Find the top 3 most popular pizza types based on revenue. ✅
- Find the percentage contribution of each pizza category to total sales. ✅
- Identify which pizza category generated the highest revenue. ⏳ Pending
- Find the revenue trend for the last 6 months. ⏳ Pending
- Determine the customer’s favorite pizza size over time. ⏳ Pending
- Rank the pizzas based on sales quantity. ⏳ Pending
- Find the most common order time (morning, afternoon, evening, night). ⏳ Pending
- Identify the day of the week with the highest sales. ⏳ Pending
- Analyze revenue trends based on pizza size. ⏳ Pending
- Retrieve the name of the least ordered pizza type. ⏳ Pending
- Calculate the cumulative revenue over time. ✅
- Find the pizza type that contributes the most revenue. ✅
- Determine the revenue trend for different pizza sizes. ✅
- Rank pizza categories based on total revenue. ✅
- Find the percentage contribution of each pizza type to the total revenue. ✅
- Identify the top-selling pizza for each pizza category. ⏳ Pending
- Analyze order patterns based on time intervals (e.g., morning, afternoon, night). ⏳ Pending
- Determine the most profitable pizza category over the last year. ⏳ Pending
- Find the average revenue generated per order. ⏳ Pending
- Compare pizza sales between weekdays and weekends. ⏳ Pending
- Find the revenue distribution based on pizza ingredients. ⏳ Pending
- Analyze monthly trends in pizza sales. ⏳ Pending
- Determine the highest revenue-generating hour of the day. ⏳ Pending
- Identify patterns in order frequency for specific pizza categories. ⏳ Pending
- Analyze sales seasonality (trends over different months). ⏳ Pending
- Retrieve the total number of distinct orders.
SELECT COUNT(DISTINCT order_id) FROM orders;
- Find the number of orders placed on each date.
SELECT date, COUNT(order_id) FROM orders GROUP BY date;
- Get the total revenue from all pizza sales.
SELECT ROUND(SUM(order_details.quantity * pizzas.price),2) AS total_sales FROM order_details JOIN pizzas ON pizzas.pizza_id = order_details.pizza_id;
- Identify the highest-priced pizza.
SELECT pt.name, MAX(p.price) FROM pizza_types pt JOIN pizzas p ON pt.pizza_type_id = p.pizza_type_id GROUP BY pt.name ORDER BY MAX(p.price) DESC LIMIT 1;
- Find the most common pizza size ordered.
SELECT pizzas.size, COUNT(order_details.order_details_id) AS order_count FROM pizzas JOIN order_details ON pizzas.pizza_id = order_details.pizza_id GROUP BY pizzas.size ORDER BY order_count DESC;
6-15. Pending Queries ⏳
- Identify the top 3 most expensive pizzas.
select pizzas.pizza_id, pizza_types.name, pizzas.price as costly_pizza from pizza_types join pizzas on pizza_types.pizza_type_id = pizzas.pizza_type_id order by costly_pizza desc limit 3;
- Identify the top 5 most ordered pizza types by quantity.
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 JOIN order_details ON order_details.pizza_id = pizzas.pizza_id GROUP BY pizza_types.name ORDER BY quantity DESC LIMIT 5;
- Determine the number of orders placed during each hour of the day.
SELECT HOUR(time) AS hour, COUNT(order_id) AS order_count FROM orders GROUP BY HOUR(time);
- Calculate the average order quantity per order.
SELECT ROUND(AVG(quantity),2) AS avg_order_quantity FROM order_details;
- Find the distribution of pizza categories across all orders.
SELECT pizza_types.category AS pizza_category, SUM(order_details.quantity) AS total_quantity, ROUND((SUM(order_details.quantity) / (SELECT SUM(quantity) FROM order_details)) * 100, 2) AS category_percentage FROM order_details JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id JOIN pizza_types ON pizzas.pizza_type_id = pizza_types.pizza_type_id GROUP BY pizza_types.category ORDER BY total_quantity DESC;
- Get the total number of pizzas ordered for each day.
SELECT orders.date, SUM(order_details.quantity) AS total_pizzas_ordered FROM orders JOIN order_details ON orders.order_id = order_details.order_id GROUP BY orders.date ORDER BY orders.date;
- Find the top 3 most popular pizza types based on revenue.
SELECT
pizza_types.name AS pizza_name,
ROUND(SUM(order_details.quantity * pizzas.price), 2) AS total_revenue
FROM order_details
JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id
JOIN pizza_types ON pizzas.pizza_type_id = pizza_types.pizza_type_id
GROUP BY pizza_types.name
ORDER BY total_revenue DESC
LIMIT 3;
- Find the percentage contribution of each pizza category to total sales.
SELECT pizza_types.category AS pizza_category, ROUND(SUM(order_details.quantity * pizzas.price), 2) AS category_revenue, ROUND((SUM(order_details.quantity * pizzas.price) / (SELECT SUM(order_details.quantity * pizzas.price) FROM order_details JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id)) * 100, 2) AS category_percentage FROM order_details JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id JOIN pizza_types ON pizzas.pizza_type_id = pizza_types.pizza_type_id GROUP BY pizza_types.category ORDER BY category_revenue DESC;
9-15. Pending Queries ⏳
- Calculate the cumulative revenue over time.
SELECT orders.date, SUM(order_details.quantity * pizzas.price) AS daily_revenue, SUM(SUM(order_details.quantity * pizzas.price)) OVER (ORDER BY orders.date) AS cumulative_revenue FROM orders JOIN order_details ON orders.order_id = order_details.order_id JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id GROUP BY orders.date ORDER BY orders.date;
- Find the pizza type that contributes the most revenue.
SELECT pt.name, ROUND(SUM(od.quantity * p.price),2) AS total_revenue FROM order_details od JOIN pizzas p ON od.pizza_id = p.pizza_id JOIN pizza_types pt ON p.pizza_type_id = pt.pizza_type_id GROUP BY pt.name ORDER BY total_revenue DESC LIMIT 1;
- Determine the revenue trend for different pizza sizes.
SELECT orders.date, pizzas.size AS pizza_size, ROUND(SUM(order_details.quantity * pizzas.price), 2) AS total_revenue FROM orders JOIN order_details ON orders.order_id = order_details.order_id JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id GROUP BY orders.date, pizzas.size ORDER BY orders.date, total_revenue DESC;
- Rank pizza categories based on total revenue.
SELECT pizza_types.category AS pizza_category, ROUND(SUM(order_details.quantity * pizzas.price), 2) AS total_revenue, RANK() OVER (ORDER BY SUM(order_details.quantity * pizzas.price) DESC) AS revenue_rank FROM order_details JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id JOIN pizza_types ON pizzas.pizza_type_id = pizza_types.pizza_type_id GROUP BY pizza_types.category;
- Find the percentage contribution of each pizza type to the total revenue.
SELECT
pizza_types.name AS pizza_name,
ROUND(SUM(order_details.quantity * pizzas.price), 2) AS pizza_revenue,
ROUND((SUM(order_details.quantity * pizzas.price) /
(SELECT SUM(order_details.quantity * pizzas.price)
FROM order_details
JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id)) * 100, 2) AS revenue_percentage
FROM order_details
JOIN pizzas ON order_details.pizza_id = pizzas.pizza_id
JOIN pizza_types ON pizzas.pizza_type_id = pizza_types.pizza_type_id
GROUP BY pizza_types.name
ORDER BY pizza_revenue DESC;
6-15. Pending Queries ⏳
📁 pizzahut-sql-analysis
│-- 📝 README.md
│-- 📄 pizza_analysis.sql
│-- 📊 queries/
│ ├── basic_queries.sql
│ ├── intermediate_queries.sql
│ ├── advanced_queries.sql
│-- 💁️ screenshots/
│ ├── schema.png
│ ├── query_results.png
│ ├── insights.png
- Implement stored procedures for automation.
- Use SQL views for common queries.
- Integrate Power BI / Tableau for better visualization.
- Use machine learning to predict pizza sales trends.
If you find this project helpful, please ⭐ the repo and share it with others! 🚀