Skip to content

Commit be43bfe

Browse files
authored
Add files via upload
1 parent 4577a82 commit be43bfe

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

Projects/ 8_Week_SQL_Challenge/Case_Study_2/Solution.sql

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,24 @@ GROUP BY
233233
ORDER BY
234234
order_hour ASC;
235235

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?
237243

238244
SELECT
239245
DATENAME(WEEKDAY, order_time) AS order_day,
240246
DATEPART(DAY, order_time) AS order_day_2,
241-
DATEPART(HOUR, order_time) AS order_hour,
242247
COUNT(pizza_id) AS count_of_pizza
243248

244249
FROM
245250
pizza_runner.customer_orders
246251
GROUP BY
247-
DATEPART(HOUR, order_time),
248252
DATENAME(WEEKDAY, order_time),
249-
DATEPART(DAY, order_time)
250-
ORDER BY
251-
order_day_2 ASC;
253+
DATEPART(DAY, order_time);
252254

253255
-- B. Runner and Customer Experience
254256
-- Question 1) How many runners signed up for each 1 week period? (i.e. week starts 2021-01-01)
@@ -260,7 +262,7 @@ FROM
260262
WITH CTE AS (
261263
SELECT
262264
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
264266
FROM
265267
pizza_runner.runners)
266268
SELECT
@@ -271,4 +273,25 @@ FROM
271273
GROUP BY
272274
week_number
273275
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

Comments
 (0)