Cancellation rate by room type

conditional logic

Cancellation rate by room type

Airbnb SQL Interview Question

Airbnb's trust team suspects that some kinds of stays get canceled more often than others. Every booking is for a listing, and each listing is an entire home, a private room or a shared room.

For each room_type, find the percentage of bookings that were canceled, as cancellation_rate_pct, rounded to 1 decimal place. Use all of that room type's bookings as the total.

Asked of

  • Data Analyst
  • BI Analyst
  • Product Analyst
  • Data Scientist

bookingsTable16 rows

Column NameType
booking_idBIGINT
listing_idBIGINT
guest_idBIGINT
check_inDATE
check_outDATE
statusVARCHAR

listingsTable10 rows

Column NameType
listing_idBIGINT
host_idBIGINT
cityVARCHAR
room_typeVARCHAR
price_per_nightBIGINT

bookingsExample Input

booking_idlisting_idguest_idcheck_incheck_outstatus
50011012012024-06-012024-06-05completed
50021032022024-06-022024-06-04completed
50031062032024-06-032024-06-10completed
50041022042024-06-052024-06-06canceled
50051042052024-06-072024-06-09completed
50061092062024-06-082024-06-11canceled
50071102072024-06-102024-06-15completed
50081052082024-06-122024-06-13completed
50091072092024-06-142024-06-16completed
50101012102024-06-152024-06-18canceled

listingsExample Input

listing_idhost_idcityroom_typeprice_per_night
10111LisbonEntire home120
10211LisbonPrivate room55
10312ParisEntire home210
10413ParisPrivate room85
10513ParisShared room40
10614TokyoEntire home160
10715TokyoPrivate room70
10816LisbonShared room30
10917TokyoEntire home190
11012ParisEntire home240

Example Output

room_typecancellation_rate_pct
Entire home33.3
Private room33.3
Shared room0

Explanation

Entire homes have 6 bookings in the example, and 2 of them were canceled, which is 33.3%. Private rooms have 1 cancellation out of 3 bookings, also 33.3%. The one shared room booking went ahead, so shared rooms have a rate of 0.

The example above is a small slice of the data. Your query runs against the full tables.