Find pairs of CONFIRMED bookings on the same listing whose stays overlap. Nights run from `check_in` up to (not including) `check_out`, so a booking that checks in on the day another checks out does NOT overlap. Cancelled bookings are ignored. Return `listing_id`, `booking_a`, `booking_b` (booking_a < booking_b), `overlap_nights` (number of shared nights, integer). Order by `listing_id`, `booking_a`, `booking_b`.
| Column | Type |
|---|---|
| booking_id | INTEGER |
| listing_id | INTEGER |
| check_in | DATE |
| check_out | DATE |
| status | TEXT |
| booking_id | listing_id | check_in | check_out | status |
|---|---|---|---|---|
| 1 | 100 | 2026-06-01 | 2026-06-05 | confirmed |
| 2 | 100 | 2026-06-04 | 2026-06-07 | confirmed |
| 3 | 100 | 2026-06-07 | 2026-06-09 | confirmed |
| 4 | 100 | 2026-06-02 | 2026-06-03 | cancelled |
| 5 | 200 | 2026-06-10 | 2026-06-15 | confirmed |
| 6 | 200 | 2026-06-11 | 2026-06-13 | confirmed |
| 7 | 300 | 2026-06-01 | 2026-06-30 | confirmed |
| listing_id | booking_a | booking_b | overlap_nights |
|---|---|---|---|
| 100 | 1 | 2 | 1 |
| 200 | 5 | 6 | 2 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Binge Watchers Within 24 Hours · Monthly Occupancy with Stays Split Across Months ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.