Slowest package per facility

ranking

Slowest package per facility

Amazon SQL Interview Question

Amazon reviews fulfillment centers on their worst case rather than their average, because the average is carried by thousands of ordinary packages while the complaint comes from the one that took a day. Each center brings its slowest package of the day to the morning stand-up.

For each facility, return the facility, the package_id that took longest, and the hours between its first and last scan as hours_in_flight, rounded to 2 decimal places.

Asked of

  • Data Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist

amazon_fulfillment_scansTable24 rows

Column NameType
scan_idBIGINT
package_idVARCHAR
facilityVARCHAR
scanned_atTIMESTAMP
stageVARCHAR

amazon_fulfillment_scansExample Input

scan_idpackage_idfacilityscanned_atstage
101P001BLR12024-11-01 09:05:00received
102P001BLR12024-11-01 10:20:00picked
103P001BLR12024-11-01 11:15:00packed
104P001BLR12024-11-01 13:40:00shipped
105P001BLR12024-11-02 09:30:00delivered
123P006HYD32024-11-01 07:50:00received
124P006HYD32024-11-01 09:40:00picked

Example Output

facilitypackage_idhours_in_flight
BLR1P00124.42
HYD3P0061.83

Explanation

P001 took 24.42 hours from its first scan to its last, the slowest in BLR1. HYD3 has only P006 in the example, at 1.83 hours, so that is its slowest by default.

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