Calculating Available Seats on Flights
 

Calculate the number of seats not yet purchased for each flight. Use three tables: playground.flights (with columns: flight_id, plane_id), playground.planes (with columns: plane_id, number_of_seats), and playground.purchases (with columns: flight_id, seat_no). Each row in purchases is unique for (flight_id, seat_no) pairs. For each flight_id, compute the free_seats as the number of seats not purchased. Order the results by flight_id in ascending order. Ensure consistency in purchases, with no records for non-existing flight_ids or seat_nos.

These are the tables to query for this question:
playground.flights
  • flight_id int
  • plane_id int
playground.planes
  • plane_id int
  • number_of_seats int
playground.purchases
  • flight_id int
  • seat_no int
Your answer should include these columns:
  • flight_id integer
  • free_seats integer

Querying is only for logged in users!

Write Your Query Here (you can run selections by highlighting!)

Query Results

No queries have been run yet.