Airbnb-style Company ChallengeBeginnerVerified answerSQLite live

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_idINTEGER
  • user_idINTEGER
  • listing_idINTEGER
  • nightsINTEGER

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_id

Why 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_iduser_idlisting_idnights
2325
4544
7864
11214

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Interview Practice

Return to the complete interview preparation experience.