Minutes from order to doorstep

dates

Minutes from order to doorstep

Instacart SQL Interview Question

Instacart logs a status event each time an order moves forward, from placed to delivered. The operations team wants to know how long delivered orders took.

For every order that was delivered, return the order_id and the minutes between its placed event and its delivered event as minutes_to_deliver, rounded to 1 decimal place. Sort by order_id.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer

eventsTable12 rows

Column NameType
event_idBIGINT
order_idBIGINT
statusVARCHAR
event_timeTIMESTAMP

eventsExample Input

event_idorder_idstatusevent_time
15001placed2024-09-10 09:00:12
25002placed2024-09-10 09:04:40
35001shopping2024-09-10 09:12:05
45003placed2024-09-10 09:15:30
55002shopping2024-09-10 09:21:18
65001delivered2024-09-10 10:02:47
75004placed2024-09-10 10:05:00
85003canceled2024-09-10 10:07:33
95002out for delivery2024-09-10 10:15:09
105004shopping2024-09-10 10:31:52
115005placed2024-09-10 10:40:26
125002delivered2024-09-10 11:01:14

Example Output

order_idminutes_to_deliver
500162.6
5002116.6

Explanation

Order 5001 was placed at 9:00:12 and delivered at 10:02:47, 62 minutes and 35 seconds later, which is 62.6 minutes. Order 5003 was canceled and orders 5004 and 5005 have not been delivered, so they are left out.

The example above is a small slice of the data. Your query runs against the full tables.