Forum

Posted by gurpreet, Nov. 25, 2021, 12:42 p.m.

SQL#136

My answer is differing a little from the actual result posted.
Query below:
With delivery_flagged as (
SELECT a.order_id,
extract(year from b.created_at) as year,
extract(month from b.created_at) as mon,
case when EXTRACT (EPOCH FROM a.delivered_at - b.created_at)::int/60 > 60
then 1
else 0 end as time_flag
FROM food_delivery a, food_order b
WHERE a.order_id = b.order_id
AND extract(year from b.created_at) = 2021
)
SELECT year,
mon,
sum(time_flag)*100.0/count(time_flag) as percent
FROM delivery_flagged
GROUP BY year, mon

Answers

Thanks Gurpreet, your solution is correct!
The solution used >= 60 minutes as the definition of late orders, but it should be >60 minutes. Just updated the solution.

Hi Leon, I just did this problem and it looks like the solution was not updated to be >60 minutes.

Iris, June 25, 2022, 8:55 a.m.

Thanks Iris, will double-check our solution!

Leon, June 25, 2022, 9:12 a.m.
SQLPad user avatar

Leon (949)

Nov. 26, 2021, 8:37 a.m.