ZZomato·BehavioralL3Machine Coding

Design a Flights Database and Write SQL Queries for Passengers

viaGlassdoor

Requirements: Design a relational database schema for a flights booking system, then write SQL queries to answer passenger-related questions (e.g., which passengers are on a given flight, which flights a passenger has booked).

Design considerations: Core entities - Flights, Passengers, Bookings (junction table linking passengers to flights with seat/booking info), Airports, and possibly Airlines. Bookings should be a many-to-many relationship between Passengers and Flights.

Approach: Define tables: flights(id, flight_no, origin, destination, departure_time, arrival_time), passengers(id, name, email), bookings(id, flight_id, passenger_id, seat_no, booking_time). Sample query - "find all passengers on flight X": SELECT p.* FROM passengers p JOIN bookings b ON p.id = b.passenger_id WHERE b.flight_id = X. Discuss indexing on flight_id/passenger_id in bookings for query performance.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account