Airbnb wants to know how many nights an active listing typically sits empty. A booking occupies every night from check_in up to but not including check_out. Only nights between 2025-01-01 and 2025-12-31 count, so bookings that cross into or out of 2025 contribute only their 2025 nights. A listing's vacant nights are 365 minus its booked 2025 nights; bookings for the same listing never overlap. Active listings (is_active = 1) with no bookings are vacant all 365 nights, and inactive listings are ignored. Write an SQL query that returns a single column, avg_vacant_nights: the average vacant nights across active listings, rounded to the nearest whole number.
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.