Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
SQL for Three Questions
00:00
5 left

SQL for Three Questions

HardSQL · PostgreSQL

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
Interviewer

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