-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYoutube_tutorial_Quries.sql
More file actions
115 lines (108 loc) · 2.42 KB
/
Youtube_tutorial_Quries.sql
File metadata and controls
115 lines (108 loc) · 2.42 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Baseic
-- Retrieve the total number of orders placed.
SELECT
COUNT(order_id) AS total_orders
FROM
orders;
Result: The total number of orders placed is 21,350.
Calculate the total revenue generated from 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;
Result: The total revenue generated is 817,860.05.
Identify the highest-priced pizza.
SELECT
pizza_types.name,
pizzas.price
FROM
pizza_types
JOIN
pizzas ON pizza_types.pizza_type_id = pizzas.pizza_type_id
ORDER BY
pizzas.price DESC
LIMIT 1;
Result: The highest-priced pizza is the The Greek Pizza with a price of 35.95.
Identify 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
LIMIT 1;
Result: The most common pizza size ordered is Large.
List the top 5 most ordered pizza types along with their quantities.
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;
Result:
Classic Deluxe Pizza: 2,453
Barbecue Chicken Pizza: 2,432
Hawaiian Pizza: 2,422
Pepperoni Pizza: 2,418
Thai Chicken Pizza: 2,370
-- Intermediate Queries section:
-- Join the necessary tables to find the total quantity of each pizza category ordered.
SELECT
pizza_types.category,
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.category
ORDER BY
quantity DESC;
Result:
Classic: 14,888
Supreme: 11,947
Veggie: 11,623
Chicken: 11,050
Determine the distribution of orders by hour of the day.
SELECT
HOUR(order_time) AS hour,
COUNT(order_id) AS order_count
FROM
orders
GROUP BY
HOUR(order_time)
ORDER BY
hour;
Result: The video shows the distribution of orders across different hours, indicating peak times around 12-1 PM and 4-7 PM.
Join relevant tables to find the category-wise distribution of pizzas.
SELECT
category,
COUNT(name) AS pizza_count
FROM
pizza_types
GROUP BY
category
ORDER BY
pizza_count DESC;
Result:
Classic: 8 pizzas
Supreme: 9 pizzas
Veggie: 9 pizzas
Chicken: 6 pizzas