Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Therapists by State

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

Your question is Top Therapists by State. 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

Grow Therapy wants to identify the therapists with the highest booking volume in each state. Assume the reporting date is January 15, 2025, so the last completed quarter is October 1 through December 31, 2024.

Write a PostgreSQL query to find the top three therapists by booking volume in each state on the Grow Therapy platform.

Requirements

  1. Count only bookings with status confirmed or completed.
  2. Include bookings created from 2024-10-01 through 2024-12-31, inclusive.
  3. Rank therapists independently within each non-null state and return up to three therapists per state.
  4. Sort each state by booking volume descending, using therapist ID as a deterministic tie-breaker.

Schema

therapists
ColumnTypeDescription
therapist_idPKINTEGERUnique therapist identifier
therapist_nameVARCHAR(100)Therapist display name
stateVARCHAR(2)Two-letter practice state
bookings
ColumnTypeDescription
booking_idPKINTEGERUnique booking identifier
therapist_idINTEGERReferences therapists.therapist_id
booking_dateDATEDate the booking was created
booking_statusVARCHAR(20)Booking lifecycle status
Tablestherapistsbookings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results