Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Best Expected Revenue Listing

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Best Expected Revenue Listing. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Turing wants to identify the listing with the highest expected revenue from the previous 12 months. Assume 60% of guests leave reviews, and every guest stays exactly the listing's minimum number of nights.

Write a PostgreSQL query using listings and reviews to return the single best listing.

Requirements

  1. Consider reviews from the rolling 12-month period before CURRENT_DATE.
  2. Include only listings where minimum_nights <= 7 and nightly_price is available.
  3. Estimate guests as review_count / 0.60.
  4. Calculate expected revenue as estimated guests multiplied by minimum_nights and nightly_price.
  5. Use a window function to rank listings and return the highest-revenue listing, breaking ties by listing_id.

Schema

listings
ColumnTypeDescription
listing_idPKINTEGERUnique listing identifier
listing_nameVARCHAR(120)Public listing name
cityVARCHAR(80)City where the listing is located
nightly_priceNUMERIC(10,2)Price charged per night
minimum_nightsINTEGERMinimum number of nights per stay
reviews
ColumnTypeDescription
review_idPKINTEGERUnique review identifier
listing_idINTEGERListing associated with the review
reviewer_nameVARCHAR(100)Name of the reviewing guest
review_dateDATEDate the review was submitted
Tableslistingsreviews
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results