Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Refactoring a Slow Query
00:00
5 left

Refactoring a Slow Query

MediumSQL · PostgreSQL

Problem

Describe a time you had to refactor a slow-performing query at Candid Health.

For this exercise, demonstrate the refactored PostgreSQL query against the provided claims data. Limit the analysis to claims submitted during 2024 and return monthly payer-level operational metrics.

Output

  1. One row per payer and submission month
  2. Columns: payer_name, submission_month, submitted_claims, resolved_claims, total_paid, denial_rate_pct, and prior_month_paid
  3. Include claims with no payment or incomplete payer details
  4. Sort by payer name ascending, with missing payer names last, then submission month ascending

Schema

claims
ColumnTypeDescription
claim_idPKINTUnique claim identifier
payer_idINTIdentifier of the payer associated with the claim
submitted_atTIMESTAMPTimestamp when the claim was submitted
billed_amountNUMERIC(12,2)Amount billed on the claim
claim_events
ColumnTypeDescription
event_idPKINTUnique event identifier
claim_idINTClaim associated with the event
event_typeVARCHAR(30)Claim lifecycle status
event_atTIMESTAMPTimestamp when the event occurred
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
claim_idINTClaim associated with the payment
paid_atDATEDate the payment was recorded
amountNUMERIC(12,2)Payment amount, which may be unknown
payers
ColumnTypeDescription
payer_idPKINTUnique payer identifier
payer_nameVARCHAR(100)Payer display name
Tablesclaimsclaim_eventspaymentspayers
Interviewer

Your question is Refactoring a Slow Query. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.