-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOS_Performance_Analysis.sql
More file actions
136 lines (104 loc) · 3.94 KB
/
Copy pathPOS_Performance_Analysis.sql
File metadata and controls
136 lines (104 loc) · 3.94 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- PROJECT OBJECTIVES:
-- 1. Dig into the customer datastet to see which menu items are doing well/not well
-- 2. See what the top customers seem to like best
-- 3. See how customers are reacting to the menu
SELECT * FROM public.menu_items
SELECT * FROM public.order_details
-- How many items are on the menu?
SELECT COUNT (menu_item_id) FROM public.menu_items
-- What are the most expensive items on the menu?
SELECT item_name, price FROM public.menu_items
ORDER BY price DESC
LIMIT 10
-- What are the least expensive items on the menu?
SELECT item_name, price FROM public.menu_items
ORDER BY price
LIMIT 10
-- How many italian dishes are on the menu?
SELECT COUNT (category) FROM public.menu_items AS Italian_dishes
WHERE category ILIKE 'italian'
-- What are the least and most expensive italian dishes on the menu?
SELECT MIN(price) FROM public.menu_items
WHERE category ILIKE 'italian'
SELECT MAX(price) FROM public.menu_items
WHERE category ILIKE 'italian'
SELECT MIN(price), MAX(price) FROM public.menu_items
WHERE category ILIKE 'italian'
-- How many dishes are in each category?
SELECT COUNT (item_name), category FROM public.menu_items
GROUP BY category
-- What is the average dish price within each category?
SELECT category, AVG(price) FROM public.menu_items
GROUP BY category
-- What is the date range of the table?
SELECT * FROM public.order_details
SELECT MIN(order_date), MAX (order_date) FROM public.order_details
-- How many orders were made within this date range?
SELECT COUNT(DISTINCT(order_id))FROM public.order_details
-- How many items were ordered within this date range?
SELECT COUNT (*) FROM public.order_details
SELECT * FROM public.menu_items
SELECT * FROM public.order_details
-- Which orders had the most number of items?
SELECT order_id, COUNT(item_id) FROM public.order_details
GROUP BY order_id
ORDER BY COUNT(item_id) DESC
-- How many orders had more than 12 items?
SELECT COUNT(*) FROM(SELECT order_id, COUNT(item_id) FROM public.order_details
GROUP BY order_id
HAVING COUNT(item_id) > 12) AS item_count
--What were the least and most ordered items?
SELECT * FROM public.menu_items
SELECT * FROM public.order_details
SELECT * FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
--Most
SELECT item_name, COUNT(order_details_id)
FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
GROUP BY item_name
ORDER BY COUNT(order_details_id) DESC
--Least
SELECT item_name, COUNT(order_details_id)
FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
GROUP BY item_name
ORDER BY COUNT(order_details_id) ASC
-- What categories were they in?
SELECT item_name, category, COUNT(order_details_id)
FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
GROUP BY item_name, category
ORDER BY COUNT(order_details_id) DESC
-- What were the top 5 orders that spent the most money?
SELECT order_id, SUM(price) AS total_spend
FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
GROUP BY order_id
ORDER BY total_spend DESC
LIMIT 5
--View the details of the highest spend order
SELECT category, COUNT(item_id) as num_items
FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
WHERE order_id = 440
GROUP BY category
--View the details of the top 5 highest spend orders
SELECT category, COUNT(item_id) as num_items
FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
WHERE order_id IN (440, 2075, 1957, 330, 2675)
GROUP BY category
SELECT order_id, category, COUNT(item_id) as num_items
FROM public.menu_items pmi
LEFT JOIN public.order_details pod
ON pmi.menu_item_id = pod.item_id
WHERE order_id IN (440, 2075, 1957, 330, 2675)
GROUP BY order_id, category