Extended Stays
Return booking_id, user_id, listing_id, and nights for bookings with more than 3 nights, ordered by booking_id.
- Filtering
- Sorting
Challenge brief
Understand the request
Host Relations Host Relations wants to identify longer-stay bookings to assess whether extended-stay pricing incentives are being used.
List bookings where guests stayed more than 3 nights.
Return
- booking_id
- user_id
- listing_id
- nights
Constraints
- Include bookings longer than three nights
- Order by booking ID
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
bookings
booking_idINTEGERuser_idINTEGERlisting_idINTEGERnightsINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Stay length is recorded on each booking.
Hint 2
The boundary excludes exactly three nights.
Hint 3
Use the booking key for stable order.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT booking_id, user_id, listing_id, nights FROM bookings WHERE nights > 3 ORDER BY booking_idWhy this works
WHERE nights > 3 keeps only stays of 4 nights or more. Including user_id and listing_id gives the host relations team context about who booked which property.
Success check
Returns all stays of four or more nights in stable booking order
Expected result
Use this output to verify values, aliases, ordering, and row count.
| booking_id | user_id | listing_id | nights |
|---|---|---|---|
| 2 | 3 | 2 | 5 |
| 4 | 5 | 4 | 4 |
| 7 | 8 | 6 | 4 |
| 11 | 2 | 1 | 4 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Uber
Independent Uber-style mobility marketplace SQL practice covering trips, drivers, riders, pricing, payments, and promotions.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Meta
Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice.
Return to the complete interview preparation experience.