-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path-- Basic_questions.sql
More file actions
58 lines (45 loc) · 1.04 KB
/
-- Basic_questions.sql
File metadata and controls
58 lines (45 loc) · 1.04 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
-- BASIC QUESTIONS
-- Retrieve the total number of orders placed.
SELECT
COUNT(order_id)
FROM
orders;
-- Calculate the total revenue generated from pizza sales.
SELECT
ROUND(SUM(order_details.quantity * pizzas.price),2) AS Total_Revenue
FROM
order_details
JOIN
pizzas ON order_details.pizza_id = pizzas.pizza_id;
-- Identify the highest-priced pizza.
SELECT
pt.name, p.price
FROM
pizza_types pt
join pizzas p on pt.pizza_type_id = p.pizza_type_id
order by p.price desc
limit 1;
-- Identify the most common pizza size ordered.
SELECT
p.size,
COUNT(od.order_details_id) AS order_count
FROM
pizzas p
join
order_details od on p.pizza_id = od.pizza_id
GROUP BY p.size
ORDER BY order_count DESC;
-- List the top 5 most ordered pizza types
-- along with their quantities.
SELECT
pt.name,
SUM(od.quantity) AS quantity
FROM
pizza_types pt
JOIN
pizzas p ON pt.pizza_type_id = p.pizza_type_id
JOIN
order_details od ON od.pizza_id = p.pizza_id
GROUP BY pt.name
ORDER BY quantity DESC
LIMIT 5;