Problem · Database
Rank Flights by Airline and Destination Frequency
Problem statement
You are given a flights table. Return one output row for every flight.
Output exactly the columns id, destination, and departure_time.
Ordering
- Airlines with more total flights come first.
- If two airlines have the same total, order them by
aviacompanyin ascending order. - Within an airline, destinations with more flights for that airline come first.
- If two destinations for the same airline have the same count, order them by
destinationin ascending order. - Within an airline and destination, order rows by
departure_timein ascending order. - If all preceding sort keys tie, order rows by
idin ascending order.
Compute both flight counts from all rows in the input table. The duration column is not returned and does not affect the ordering.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
flights
Flight records used to compute airline and destination frequencies.
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | Unique flight identifier. |
| aviacompany | Text | No | Airline operating the flight. |
| destination | Text | No | Flight destination code. |
| departure_time | Text | No | Zero-padded departure time in HH-MM format. |
| duration | Integer | No | Flight duration in minutes. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| id | Integer | No | — |
| destination | Text | No | — |
| departure_time | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The
idcolumn uniquely identifies a flight. - Every input cell is non-null.
aviacompanyanddestinationcontain non-empty uppercase ASCII letters and spaces.departure_timeis a zero-padded 24-hour time inHH-MMformat.durationis an integer number of minutes.- The
flightstable may be empty.