Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Routes by Delay

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Routes by Delay. Start with the requirements and the two tables on the right.

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.

Problem

Delta Air Lines wants to identify routes with the highest average arrival delays during the last completed quarter. Assume the reporting period is April 1, 2025 through June 30, 2025. Write a PostgreSQL query that ranks routes by their average arrival delay.

Requirements

  1. Join flight records to Delta's route reference table.
  2. Include only flights within the reporting period and exclude cancelled flights.
  3. Calculate the average non-null arrival delay in minutes for each route, rounded to two decimal places.
  4. Return the top three routes, breaking ties by route_code alphabetically.

Schema

routes
ColumnTypeDescription
route_idPKINTUnique route identifier
route_codeVARCHAR(20)Route label formed from origin and destination
origin_airportVARCHAR(3)Origin airport code
destination_airportVARCHAR(3)Destination airport code
flight_records
ColumnTypeDescription
flight_idPKINTUnique flight record identifier
route_idINTReferences routes.route_id
flight_dateDATEScheduled flight date
arrival_delay_minutesINTArrival delay in minutes
is_cancelledBOOLEANWhether the flight was cancelled
Tablesroutesflight_records
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results