@@ -158,7 +158,10 @@ GROUP BY
158
158
) AS subquery;
159
159
160
160
-- Question 7) For each customer, how many delivered pizzas had at least 1 change and how many had no changes?
161
-
161
+ SELECT
162
+ *
163
+ FROM
164
+ pizza_runner .customer_orders ;
162
165
163
166
WITH order_changes AS (
164
167
@@ -199,7 +202,7 @@ GROUP BY
199
202
) AS subquery
200
203
201
204
WHERE
202
- exclusions_with_extras != 0
205
+ exclusions_with_extras != 0 ;
203
206
204
207
205
208
-- Solution II
@@ -209,6 +212,63 @@ SELECT
209
212
FROM
210
213
pizza_runner .customer_orders
211
214
WHERE
212
- exclusions IS NOT NULL AND extras IS NOT NULL
215
+ exclusions IS NOT NULL AND extras IS NOT NULL ;
216
+
217
+ -- Question 9) What was the total volume of pizzas ordered for each hour of the day?
218
+
219
+ SELECT
220
+ *
221
+ FROM
222
+ pizza_runner .customer_orders ;
223
+
224
+
225
+ SELECT
226
+ DATEPART(HOUR, order_time) AS order_hour,
227
+ COUNT (pizza_id) AS count_of_pizza
228
+
229
+ FROM
230
+ pizza_runner .customer_orders
231
+ GROUP BY
232
+ DATEPART(HOUR, order_time)
233
+ ORDER BY
234
+ order_hour ASC ;
213
235
214
- -- Question 9) What was the total volume of pizzas ordered for each hour of the day?
236
+ -- Question 10)What was the volume of orders for each day of the week?
237
+
238
+ SELECT
239
+ DATENAME(WEEKDAY, order_time) AS order_day,
240
+ DATEPART(DAY, order_time) AS order_day_2,
241
+ DATEPART(HOUR, order_time) AS order_hour,
242
+ COUNT (pizza_id) AS count_of_pizza
243
+
244
+ FROM
245
+ pizza_runner .customer_orders
246
+ GROUP BY
247
+ DATEPART(HOUR, order_time),
248
+ DATENAME(WEEKDAY, order_time),
249
+ DATEPART(DAY, order_time)
250
+ ORDER BY
251
+ order_day_2 ASC ;
252
+
253
+ -- B. Runner and Customer Experience
254
+ -- Question 1) How many runners signed up for each 1 week period? (i.e. week starts 2021-01-01)
255
+ SELECT
256
+ *
257
+ FROM
258
+ pizza_runner .runners ;
259
+
260
+ WITH CTE AS (
261
+ SELECT
262
+ registration_date,
263
+ DATEDIFF(WEEK, ' 2021-01-01' , registration_date) + 1 AS week_number
264
+ FROM
265
+ pizza_runner .runners )
266
+ SELECT
267
+ week_number,
268
+ COUNT (* ) AS count_of_runners
269
+ FROM
270
+ CTE
271
+ GROUP BY
272
+ week_number
273
+ ORDER BY
274
+ week_number;
0 commit comments