Skip to content

2112. The Airport With the Most Traffic 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
WITH
  AirportToCount AS (
    SELECT departure_airport AS airport_id, flights_count
    FROM Flights
    UNION ALL
    SELECT arrival_airport, flights_count
    FROM Flights
  ),
  RankedAirports AS (
    SELECT
      airport_id,
      RANK() OVER(ORDER BY SUM(flights_count) DESC) AS `rank`
    FROM AirportToCount
    GROUP BY 1
  )
SELECT airport_id
FROM RankedAirports
WHERE `rank` = 1;