SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Double-Booked Listings

Unsolved

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.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
🏢 Airbnb🏢 Booking.com🏢 Expedia

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM bookings
Full source dataset
11 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine