Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Delayed Routes by Region

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Top Delayed Routes by Region. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

You are given shipment records from a supply chain dataset and asked to identify the top 3 delayed routes within each region. A route is defined by an origin distribution center and destination market. Use PostgreSQL SQL to calculate the average delay in days for each route, rank routes within each region from most delayed to least delayed, and return the top 3 per region. Only include shipments that have both planned and actual delivery dates and where the shipment status is not Cancelled.

Schema

shipments
ColumnTypeDescription
shipment_idPKINTUnique shipment identifier
region_idINTRegion associated with the shipment
route_idINTRoute used for the shipment
planned_delivery_dateDATEScheduled delivery date
actual_delivery_dateDATEActual delivery date
shipment_statusVARCHAR(20)Current shipment status
regions
ColumnTypeDescription
region_idPKINTUnique region identifier
region_nameVARCHAR(50)Region name
routes
ColumnTypeDescription
route_idPKINTUnique route identifier
origin_dcVARCHAR(50)Origin distribution center
destination_marketVARCHAR(50)Destination market
Tablesshipmentsregionsroutes
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results