0% found this document useful (0 votes)
612 views

Pizza Sales SQL Queries

The document contains SQL queries to analyze pizza sales data from a table called pizza_sales. It includes queries to calculate key performance indicators like total revenue, average order value, total pizzas sold, and total orders. Additional queries analyze trends in orders by day and month. Other queries calculate percentage of sales and pizzas sold by category and size. Further queries identify top and bottom performing pizzas by revenue, quantity, and total orders.

Uploaded by

Kartikay Goswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
612 views

Pizza Sales SQL Queries

The document contains SQL queries to analyze pizza sales data from a table called pizza_sales. It includes queries to calculate key performance indicators like total revenue, average order value, total pizzas sold, and total orders. Additional queries analyze trends in orders by day and month. Other queries calculate percentage of sales and pizzas sold by category and size. Further queries identify top and bottom performing pizzas by revenue, quantity, and total orders.

Uploaded by

Kartikay Goswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DATA TUTORIALS YT CHANNEL Like, Share & Subscribe

PIZZA SALES SQL QUERIES


A. KPI’s
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 Avg_order_Value
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. Average Pizzas 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_order
FROM pizza_sales
DATA TUTORIALS YT CHANNEL Like, Share & Subscribe

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)
Output:

C. Monthly Trend for Orders


select DATENAME(MONTH, order_date) as Month_Name, COUNT(DISTINCT order_id)
as Total_Orders
from pizza_sales
GROUP BY DATENAME(MONTH, order_date)Output
DATA TUTORIALS YT CHANNEL Like, Share & Subscribe

D. % of Sales by Pizza Category


SELECT pizza_category, CAST(SUM(total_price) AS DECIMAL(10,2)) as
total_revenue,
CAST(SUM(total_price) * 100 / (SELECT SUM(total_price) from pizza_sales)
AS DECIMAL(10,2)) AS PCT
FROM pizza_sales
GROUP BY pizza_category

Output

E. % of Sales by Pizza Size


SELECT pizza_size, CAST(SUM(total_price) AS DECIMAL(10,2)) as
total_revenue,
CAST(SUM(total_price) * 100 / (SELECT SUM(total_price) from pizza_sales)
AS DECIMAL(10,2)) AS PCT
FROM pizza_sales
GROUP BY pizza_size
ORDER BY pizza_size

Output
DATA TUTORIALS YT CHANNEL Like, Share & Subscribe

F. Total Pizzas Sold by Pizza Category


SELECT pizza_category, SUM(quantity) as Total_Quantity_Sold
FROM pizza_sales
WHERE MONTH(order_date) = 2
GROUP BY pizza_category
ORDER BY Total_Quantity_Sold DESC

Output

G. Top 5 Pizzas by Revenue


SELECT Top 5 pizza_name, SUM(total_price) AS Total_Revenue
FROM pizza_sales
GROUP BY pizza_name
ORDER BY Total_Revenue DESC

H. Bottom 5 Pizzas by Revenue


SELECT Top 5 pizza_name, SUM(total_price) AS Total_Revenue
FROM pizza_sales
GROUP BY pizza_name
ORDER BY Total_Revenue ASC
DATA TUTORIALS YT CHANNEL Like, Share & Subscribe

I. Top 5 Pizzas by Quantity


SELECT Top 5 pizza_name, SUM(quantity) AS Total_Pizza_Sold
FROM pizza_sales
GROUP BY pizza_name
ORDER BY Total_Pizza_Sold DESC
Output

J. Bottom 5 Pizzas by Quantity


SELECT TOP 5 pizza_name, SUM(quantity) AS Total_Pizza_Sold

FROM pizza_sales
GROUP BY pizza_name
ORDER BY Total_Pizza_Sold ASC

Output
DATA TUTORIALS YT CHANNEL Like, Share & Subscribe

K. Top 5 Pizzas by Total Orders


SELECT Top 5 pizza_name, COUNT(DISTINCT order_id) AS Total_Orders
FROM pizza_sales
GROUP BY pizza_name
ORDER BY Total_Orders DESC

L. Borrom 5 Pizzas by Total Orders


SELECT Top 5 pizza_name, COUNT(DISTINCT order_id) AS Total_Orders
FROM pizza_sales
GROUP BY pizza_name
ORDER BY Total_Orders ASC

NOTE
If you want to apply the pizza_category or pizza_size filters to the above
queries you can use WHERE clause. Follow some of below examples
SELECT Top 5 pizza_name, COUNT(DISTINCT order_id) AS Total_Orders
FROM pizza_sales
WHERE pizza_category = 'Classic'
GROUP BY pizza_name
ORDER BY Total_Orders ASC

You might also like