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

SQL Code

The document shows SQL queries to analyze sales data from a pizza restaurant. It extracts key performance indicators like total revenue, average order value, total orders. It also analyzes trends by day, month. It calculates sales and orders by pizza category, size. It identifies top and bottom performing pizzas by revenue, quantity, number of orders.

Uploaded by

imamshauzab11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL Code

The document shows SQL queries to analyze sales data from a pizza restaurant. It extracts key performance indicators like total revenue, average order value, total orders. It also analyzes trends by day, month. It calculates sales and orders by pizza category, size. It identifies top and bottom performing pizzas by revenue, quantity, number of orders.

Uploaded by

imamshauzab11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

-----------------------------------------------Filtering Data----------------------------------------

--Removing unnesesary data

DELETE FROM pizzaorders

WHERE pizza_category NOT IN ('Supreme', 'Veggie', 'Chicken', 'Classic');

--Removing null values

DELETE FROM pizzaorders

WHERE pizza_size IS NULL;

-----------------------------------------------------------------------------------------------------

--A. KPI'S

--1. Total Revenue:

select sum(total_price) as total_revenue from pizzaorders

--2. Average Order Value

select sum(total_price)/count(distinct order_id) as avg_order from pizzaorders

--3. Total Pizzas Sold

select sum(quantity) as total from pizzaorders

--4. Total Orders

select count(distinct order_id) as total_orders from pizzaorders

--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)) avgpizza

from pizzaorders
--B. Daily Trend for Total Orders

select to_char(order_date, 'DAY') as day, count(distinct order_id) as totalorders

from pizzaorders

group by 1

order by 2 desc

--C. Monthly Trend for Orders

select to_char(order_date, 'Month') as month, count(distinct order_id) as totalorders

from pizzaorders

group by 1

order by 2 desc

--D. % of Sales by Pizza Category

select pizza_category, cast((sum(total_price)*100/(select sum(total_price) from pizzaorders)) as


decimal(10,2)) as TSP

from pizzaorders

group by 1

--E. % of Sales by Pizza Size

select pizza_size, cast((sum(total_price)*100/(select sum(total_price) from pizzaorders)) as


decimal(10,2)) as TSP

from pizzaorders

group by 1

--F. Total Pizzas Sold by Pizza Category

select pizza_category, sum(quantity) as total

from pizzaorders
group by 1

--G. Top 5 Pizzas by Revenue

select pizza_name, sum(total_price) as total

from pizzaorders

group by 1

order by 2 desc

limit 5

--H. Bottom 5 Pizzas by Revenue

select pizza_name, sum(total_price) as total

from pizzaorders

group by 1

order by 2 asc

limit 5

--I. Top 5 Pizzas by Quantity

select pizza_name, sum(quantity) as total

from pizzaorders

group by 1

order by 2 desc

limit 5

--J. Bottom 5 Pizzas by Quantity

select pizza_name, sum(quantity) as total

from pizzaorders

group by 1
order by 2 asc

limit 5

--K. Top 5 Pizzas by Total Orders

select pizza_name, count(distinct order_id) as total

from pizzaorders

group by 1

order by 2 desc

limit 5

--L. Borrom 5 Pizzas by Total Orders

select pizza_name, count(distinct order_id) as total

from pizzaorders

group by 1

order by 2 asc

limit 5

----------------------------------------------------------------------------------------------------------------

You might also like