SQL code copied to buffer
Sharpen your SQL skills with our interactive exercises and assessments!
Practice a wide range of SQL tasks, from basic queries to advanced techniques. Get immediate feedback on your solutions, helping you learn from mistakes and improve your skills. Boost your confidence for job interviews and real-world SQL applications.
Task  25:
Using the solution of the previous problem rank airports by the number of delayed flights in August 2017 (the fewer the better).
Only include airports with more than 100 departures per month.
Output the result as a table with columns:
     airport_rank - airport rating,
     airport_name - English name of the airport
     delayed_flights_rate - percentage of delayed flights accurate to two digits.
Sort the table by rating

Write your request in the field below and click the "Check it!" button.

To write the answer, use PostgreSQL syntax. Descriptions of the tables are given in the right panel.

Explore over 290 diverse tasks on our platform.

Log in to save your progress.

Bookings Database (PostgreSQL)

The subject area of this database is airline flights through various airports.

ER diagram of the Bookings database

The Bookings Database contains 8 tables:

  • aircrafts_data - table of aircraft.
  • airports_data - table of airports.
  • boarding_passes - table of boarding passes.
  • bookings - table of bookings.
  • flights - table of flights.
  • seats - table of aircraft seats.
  • ticket_flights - table of ticket to flights relations.
  • tickets - table of tickets.
Learn PostgreSQL
Learn PostgreSQL: Use, manage and build secure and scalable databases with PostgreSQL by Luca Ferrari & Enrico Pirozzi
This new edition will help you learn PostgreSQL from scratch with the latest version, providing a complete focused view on aspects like configuration, high performance, partitioning, backup, server-side programming and replication.

Table aircrafts_data

Table columns:
  • aircraft_code - Unique code for each aircraft.
  • model - Aircraft model name in English and Russian in JSON format.
  • range - Aircraft fly range in kilometers.
Indexes:
  • PRIMARY KEY, btree (aircraft_code)
aircraft_codemodelrange
1773{"en": "Boeing 777-300", "ru": "Боинг 777-300"}11100

Table airports_data

Table columns:
  • airport_code - Unique code for each airport.
  • airport_name - Airport name in English and Russian in JSON format.
  • city - Airport city in English and Russian in JSON format.
  • coordinates - Airport coordinates as POINT(longitude, latitude).
  • timezone - Airport timezone name.
airport_codeairport_namecitycoordinatestimezone
1YKS{"en": "Yakutsk Airport", "ru": "Якутск"}{"en": "Yakutsk", "ru": "Якутск"}(129.77099609375,62.0932998657227)Asia/Yakutsk
Indexes:
  • PRIMARY KEY, btree (airport_code)

Table boarding_passes

Table columns:
  • ticket_no - Ticket number.
  • flight_id - Flight identificator.
  • boarding_no - Boarding pass number.
  • seat_no - Seat number.
ticket_noflight_idboarding_noseat_no
100054352123513062512D
Indexes:
  • PRIMARY KEY, btree (ticket_no, flight_id)
  • UNIQUE CONSTRAINT, btree (flight_id, boarding_no)
  • UNIQUE CONSTRAINT, btree (flight_id, seat_no)
Foreign-key constraints:
  • FOREIGN KEY (ticket_no, flight_id) REFERENCES ticket_flights(ticket_no, flight_id)

Table bookings

Table columns:
  • book_ref - Booking number.
  • book_date - Booking date.
  • total_amount - Total booking cost.
book_refbook_datetotal_amount
100000F2017-07-05 00:12:00+00265700.00
Indexes:
  • PRIMARY KEY, btree (book_ref)

Table flights

Table columns:
  • flight_id - Flight ID.
  • flight_no - Flight number.
  • scheduled_departure - Scheduled departure time.
  • scheduled_arrival - Scheduled arrival time.
  • departure_airport - Airport of departure.
  • arrival_airport - Airport of arrival.
  • status - Flight status.
  • aircraft_code - Aircraft code, IATA.
  • actual_departure - Actual departure time.
  • actual_arrival - Actual arrival time.
flight_id flight_no scheduled_departure scheduled_arrival departure_airport arrival_airport status aircraft_code actual_departure actual_arrival
11185PG01342017-09-10 06:50:00+002017-09-10 11:55:00+00DMEBTKScheduled319
Indexes:
  • PRIMARY KEY, btree (flight_id)
  • UNIQUE CONSTRAINT, btree (flight_no, scheduled_departure)

Table seats

Table columns:
  • aircraft_code - Aircraft code, IATA.
  • seat_no - Seat number.
  • fare_conditions - Travel class.
aircraft_codeseat_nofare_conditions
13192ABusiness
Indexes:
  • PRIMARY KEY, btree (aircraft_code, seat_no)
Foreign-key constraints:
  • FOREIGN KEY (aircraft_code) REFERENCES aircrafts(aircraft_code) ON DELETE CASCADE

Table ticket_flights

Table columns:
  • ticket_no - Ticket number.
  • flight_id - Flight ID.
  • fare_conditions - Travel class.
  • amount - Travel cost.
ticket_no flight_id fare_conditions amount
1000543215977630625Business42100.00
Indexes:
  • PRIMARY KEY, btree (ticket_no, flight_id)
Foreign-key constraints:
  • FOREIGN KEY (flight_id) REFERENCES flights(flight_id)
  • FOREIGN KEY (ticket_no) REFERENCES tickets(ticket_no)

Table tickets

Table columns:
  • ticket_no - Ticket number.
  • book_ref - Booking number.
  • passenger_id - Passenger ID.
  • passenger_name - Passenger name.
  • contact_data - Passenger contact information.
ticket_no book_ref passenger_id passenger_name contact_data
1000543200098706B0468149 604011VALERIY TIKHONOV{"phone": "+70127117011"}
Indexes:
  • PRIMARY KEY, btree (ticket_no)
Foreign-key constraints:
  • FOREIGN KEY (book_ref) REFERENCES bookings(book_ref)