Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Top Delayed Routes by Region
00:00
5 left

Top Delayed Routes by Region

MediumSQL · PostgreSQL

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.

Output details

  • Return columns in this order: region_name, route_name, avg_delay_days, and route_rank.
  • Format route_name as origin_dc -> destination_market.
  • Round avg_delay_days to two decimal places.
  • Rank equal average delays by route_name ascending.
  • Sort final results by region_name ascending, route_rank ascending, then route_name ascending.

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
Interviewer

Your question is Top Delayed Routes by Region. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.