From 20ae1bda53106669ef1015b00508c55393a9e446 Mon Sep 17 00:00:00 2001 From: ATUL SINGH Date: Tue, 4 Apr 2023 15:52:11 +0530 Subject: [PATCH] Update B. Runner and Customer Experience.md I think the question is asking about the average time for each customer , so it should be grouped by runner_id. Please look into it once --- .../B. Runner and Customer Experience.md | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/Case Study #2 - Pizza Runner/B. Runner and Customer Experience.md b/Case Study #2 - Pizza Runner/B. Runner and Customer Experience.md index 3ffb1d7..7b8e81b 100644 --- a/Case Study #2 - Pizza Runner/B. Runner and Customer Experience.md +++ b/Case Study #2 - Pizza Runner/B. Runner and Customer Experience.md @@ -22,24 +22,11 @@ GROUP BY DATEPART(WEEK, registration_date); ### 2. What was the average time in minutes it took for each runner to arrive at the Pizza Runner HQ to pickup the order? ````sql -WITH time_taken_cte AS -( - SELECT - c.order_id, - c.order_time, - r.pickup_time, - DATEDIFF(MINUTE, c.order_time, r.pickup_time) AS pickup_minutes - FROM #customer_orders AS c - JOIN #runner_orders AS r - ON c.order_id = r.order_id - WHERE r.distance != 0 - GROUP BY c.order_id, c.order_time, r.pickup_time -) +select r.runner_id, avg(DATEDIFF(MINUTE,order_time,pickup_time)) as time_taken + from runner_orders r join customer_orders c on r.order_id = c.order_id + where pickup_time is not null + group by r.runner_id -SELECT - AVG(pickup_minutes) AS avg_pickup_minutes -FROM time_taken_cte -WHERE pickup_minutes > 1; ```` **Answer:**