Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Complex SQL With ERD Reasoning
00:00
5 left

Complex SQL With ERD Reasoning

HardSQL · PostgreSQL

Problem

Tell me how you would approach writing SQL for a task that requires interpreting an ERD and producing results from subqueries with calculations and conditions under tight time constraints.

For this exercise, use the provided property, booking, and payment tables. Produce the requested result while making assumptions explicit and handling missing payment records.

Output

  1. One row per qualifying property and booking month.
  2. Columns: property_name, booking_month, completed_bookings, net_revenue, average_booking_value, previous_month_revenue, revenue_change_pct, and revenue_rank.
  3. Include only months with at least two positive-value completed bookings.
  4. Order by booking month ascending, revenue rank ascending, and property name ascending.

Schema

properties
ColumnTypeDescription
property_idPKINTUnique property identifier
property_nameVARCHAR(100)Display name of the property
cityVARCHAR(80)Property city
bookings
ColumnTypeDescription
booking_idPKINTUnique booking identifier
property_idINTBooked property identifier
check_in_dateDATEGuest check-in date
booking_statusVARCHAR(20)Booking lifecycle status
total_amountDECIMAL(10,2)Total booking value
booking_payments
ColumnTypeDescription
payment_idPKINTUnique payment transaction identifier
booking_idINTRelated booking identifier
payment_statusVARCHAR(20)Payment transaction status
amountDECIMAL(10,2)Payment transaction amount
Tablespropertiesbookingsbooking_payments
Interviewer

Your question is Complex SQL With ERD Reasoning. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.