Skip to content
Quantoros

Return pairs of bookingids in the SAME room whose date ranges overlap (a.start <= b.end AND b.start <= a.end). Each…

SQLLevel: AdvancedAdvanced and misc

Return pairs of booking_ids in the SAME room whose date ranges overlap (a.start <= b.end AND b.start <= a.end). Each pair once (a.id < b.id).

Table definitions (from the source exercise):

CREATE TABLE bookings(booking_id INTEGER PRIMARY KEY, room_id TEXT, start_date TEXT, end_date TEXT);
Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

This answer is part of mentoring

Advanced questions come with a full breakdown and a mock interview with a working quant researcher. The first call is free.

Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT

Related questions