@@ -233,22 +233,24 @@ GROUP BY
233
233
ORDER BY
234
234
order_hour ASC ;
235
235
236
- -- Question 10)What was the volume of orders for each day of the week?
236
+ select DATEPART(HOUR, order_time) AS order_hour,
237
+ count (order_id)
238
+ from pizza_runner .customer_orders co
239
+ group by DATEPART(HOUR, order_time)
240
+ order by 1 ;
241
+
242
+ -- Question 10) What was the volume of orders for each day of the week?
237
243
238
244
SELECT
239
245
DATENAME(WEEKDAY, order_time) AS order_day,
240
246
DATEPART(DAY, order_time) AS order_day_2,
241
- DATEPART(HOUR, order_time) AS order_hour,
242
247
COUNT (pizza_id) AS count_of_pizza
243
248
244
249
FROM
245
250
pizza_runner .customer_orders
246
251
GROUP BY
247
- DATEPART(HOUR, order_time),
248
252
DATENAME(WEEKDAY, order_time),
249
- DATEPART(DAY, order_time)
250
- ORDER BY
251
- order_day_2 ASC ;
253
+ DATEPART(DAY, order_time);
252
254
253
255
-- B. Runner and Customer Experience
254
256
-- Question 1) How many runners signed up for each 1 week period? (i.e. week starts 2021-01-01)
260
262
WITH CTE AS (
261
263
SELECT
262
264
registration_date,
263
- DATEDIFF(WEEK , ' 2021-01-01' , registration_date) + 1 AS week_number
265
+ FLOOR( DATEDIFF(DAY , ' 2021-01-01' , registration_date) / 7 ) AS week_number
264
266
FROM
265
267
pizza_runner .runners )
266
268
SELECT
@@ -271,4 +273,25 @@ FROM
271
273
GROUP BY
272
274
week_number
273
275
ORDER BY
274
- week_number;
276
+ week_number;
277
+
278
+ -- Question 2) What was the average time in minutes it took for each runner to arrive at the Pizza Runner HQ to pickup the order?
279
+
280
+ SELECT
281
+ *
282
+ FROM
283
+ pizza_runner .runner_orders ;
284
+
285
+ SELECT
286
+ runner_id,
287
+ AVG (duration) AS average_pickup_time
288
+ FROM
289
+ pizza_runner .runner_orders
290
+ WHERE
291
+ cancellation IS NULL -- for not cancelling order
292
+ GROUP BY
293
+ runner_id
294
+ ORDER BY
295
+ runner_id;
296
+
297
+ -- Question 3) Is there any relationship between the number of pizzas and how long the order takes to prepare?
0 commit comments