Airbnb's trust and safety team needs to catch double bookings. Two bookings for the same listing overlap if each one starts before the other ends. The `check_out` date is exclusive, so a booking that checks in on the same day another one checks out does NOT overlap. Write an SQL query that returns every overlapping pair of bookings on the same listing, with columns `listing_id`, `first_booking_id`, `second_booking_id` (where `first_booking_id` is the smaller booking id, so each pair appears once) and `overlap_nights` (number of nights the two stays share). Order the results by `listing_id`, then `first_booking_id`, then `second_booking_id`, all ascending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.