Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Procedures by State

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

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

Business Context

Gainwell Technologies needs a quarterly view of medical procedure utilization across state Medicaid programs. Analysts must identify the procedures most frequently billed in each provider state.

Task

Assume the reporting date is August 29, 2026, so the last completed calendar quarter is April 1 through June 30, 2026. Write a PostgreSQL query that returns the top three billed procedures per state.

Requirements

  1. Join claims to providers, claim lines, and medical procedures.
  2. Include only claim lines with billing_status = 'BILLED' during the last completed quarter.
  3. Count billed claim lines for each state and procedure.
  4. Rank procedures independently within each state and return ranks 1 through 3.
  5. Sort by state, billed count descending, and procedure code for deterministic tie handling.

Schema

providers
ColumnTypeDescription
provider_idPKINTUnique provider identifier
provider_nameVARCHAR(150)Provider or organization name
state_codeVARCHAR(2)Two-character provider state code
taxonomyVARCHAR(100)Provider specialty classification
claims
ColumnTypeDescription
claim_idPKINTUnique claim identifier
claim_numberVARCHAR(30)External claim reference
provider_idINTReferences providers.provider_id
member_idVARCHAR(30)Medicaid member identifier
service_dateDATEDate services were provided
claim_statusVARCHAR(20)Overall claim processing status
claim_lines
ColumnTypeDescription
claim_line_idPKINTUnique claim line identifier
claim_idINTReferences claims.claim_id
procedure_idINTReferences medical_procedures.procedure_id
billing_statusVARCHAR(20)Line billing disposition
unitsINTNumber of units billed
medical_procedures
ColumnTypeDescription
procedure_idPKINTUnique procedure identifier
procedure_codeVARCHAR(10)Procedure billing code
procedure_nameVARCHAR(150)Procedure description
Tablesprovidersclaimsclaim_linesmedical_procedures
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results