Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Top Delayed Distribution Centers
00:00
5 left

SQL Top Delayed Distribution Centers

MediumSQL · PostgreSQL

Problem

Walmart's supply chain team wants to identify distribution centers with the highest average shipment delays during the previous calendar quarter. Write a SQL query that calculates the average recorded delay for each eligible distribution center and returns the three centers with the highest averages.

Output

  1. One row per distribution center, with columns distribution_center_id, center_code, center_name, and average_delay_minutes
  2. Include only shipments from the previous calendar quarter and ignore shipments whose delay is NULL
  3. Return the three centers with the highest average delay, ordered from highest to lowest average; break ties by ascending distribution_center_id

Schema

distribution_centers
ColumnTypeDescription
distribution_center_idPKINTUnique distribution center identifier
center_codeVARCHAR(20)Operational distribution center code
center_nameVARCHAR(100)Distribution center name
shipments
ColumnTypeDescription
shipment_idPKINTUnique shipment identifier
distribution_center_idINTDistribution center handling the shipment
shipment_dateDATEShipment processing date
delay_minutesDECIMAL(10,2)Shipment delay in minutes, nullable when not recorded
Tablesdistribution_centersshipments
Interviewer

Your question is SQL Top Delayed Distribution Centers. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.