Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Three Questions

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

Your question is SQL for Three Questions. Start with the requirements and the four 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

Context

RealSelf wants a recurring provider performance report covering qualified leads generated through its marketplace and the appointments associated with those leads.

Task

Write PostgreSQL queries to answer the following three questions for January through March 2025. Combine the outputs into one result set with a report_section column so each analysis can be identified.

Requirements

  1. Report monthly leads, completed appointments, and conversion rate by provider.
  2. Identify the top two providers by completed appointments each month, including each provider's three-month rolling lead count and monthly rank. Break ties alphabetically by provider name.
  3. Identify providers whose conversion rate decreased from the previous month, including the previous rate, current rate, and percentage-point change.
  4. Exclude spam leads, preserve months with zero activity for providers who had at least one valid lead, and treat cancelled or missing appointments as non-conversions.

Schema

providers
ColumnTypeDescription
provider_idPKINTUnique RealSelf provider identifier
provider_nameVARCHAR(100)Provider display name
specialtyVARCHAR(100)Primary medical specialty
procedures
ColumnTypeDescription
procedure_idPKINTUnique procedure identifier
procedure_nameVARCHAR(120)RealSelf procedure name
categoryVARCHAR(60)Procedure category
leads
ColumnTypeDescription
lead_idPKINTUnique inquiry or lead identifier
provider_idINTReferenced RealSelf provider
procedure_idINTProcedure associated with the inquiry
created_atTIMESTAMPLead creation timestamp
statusVARCHAR(30)Lead lifecycle status
sourceVARCHAR(40)Lead acquisition source
appointments
ColumnTypeDescription
appointment_idPKINTUnique appointment identifier
lead_idINTLead that produced the appointment
appointment_dateDATEScheduled appointment date
statusVARCHAR(25)Appointment outcome
revenueDECIMAL(10,2)Attributed revenue when available
Tablesprovidersproceduresleadsappointments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results