bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 2793. Status of Flight Tickets

2793. Status of Flight Tickets

Leetcode Solutions

Ranking Passengers and Comparing with Flight Capacity

  1. Create a Common Table Expression (CTE) named passenger_with_rank that selects passenger_id, flight_id, and assigns a rank using ROW_NUMBER() partitioned by flight_id and ordered by booking_time.
  2. Create another CTE named joined_data that joins passenger_with_rank with the Flights table on flight_id and selects passenger_id, rank (rk), and capacity.
  3. Select passenger_id from joined_data and use a CASE statement to check if rk is less than or equal to capacity. If true, return 'Confirmed'; otherwise, return 'Waitlist'.
  4. Order the result by passenger_id in ascending order.
erDiagram
    Flights {
        int flight_id
        int capacity
    }
    Passengers {
        int passenger_id
        int flight_id
        datetime booking_time
    }
    Flights ||--o{ Passengers : contains

Using DENSE_RANK to Handle Simultaneous Bookings

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...