Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Diagnoses by Month

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

Your question is Top Diagnoses by Month. 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

Caris Life Sciences uses molecular and clinical diagnosis data to monitor trends across its patient population. Write a PostgreSQL query that identifies the three most common diagnoses by distinct patient count for each month.

Requirements

  1. Join diagnosis_events to patient_registry and include only events for registered patients.
  2. Group records by calendar month and diagnosis, counting each patient at most once per month and diagnosis.
  3. Rank diagnoses within each month by patient count descending, using diagnosis name ascending as the deterministic tie-breaker.
  4. Return the top three diagnoses available in each month, ordered by month and rank.

Schema

patient_registry
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_codeVARCHAR(20)Caris patient reference code
sexVARCHAR(20)Recorded patient sex
diagnosis_events
ColumnTypeDescription
event_idPKINTUnique diagnosis event identifier
patient_idINTReferences patient_registry.patient_id
diagnosis_nameVARCHAR(100)Diagnosis or biomarker-associated condition
diagnosed_atDATEDate of diagnosis event
Tablespatient_registrydiagnosis_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results