logo

Back to questions

Matching Rental Amenities

Hard

The Airbnb Booking Recommendations team is trying to understand the "substitutability" of two rentals and whether one rental is a good substitute for another. They want you to write a query to determine if two Airbnb rentals have the same exact amenities offered.

Output the count of matching rental ids.

Assumptions:

  • If property 1 has kitchen and pool, and property 2 has kitchen and pool too, then it is a good substitute and represents a count of 1 matching rental.
  • If property 3 has kitchen, pool and fireplace, and property 4 only has pool and fireplace, then it is not a good substitute.

Table:

Column NameType
rental_idinteger
amenitystring

Example Input:

rental_idamenity
123pool
123kitchen
234hot tub
234fireplace
345kitchen
345pool
456pool

Example Output:

matching_airbnb
1

Explanation: The count of matching rentals is 1 as rentals 123 and 345 are a match as they both have a kitchen and a pool.

PostgreSQL 14

Refer friends to get bonus content & cool prizes.