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
Join Patient Records and Aggregate
00:00
5 left

Join Patient Records and Aggregate

MediumSQL · PostgreSQL

Problem

Novo Nordisk's clinical analytics team needs a patient-level summary of diagnostic activity from its clinical data platform. Write a PostgreSQL query that joins patient records with diagnostic codes and aggregates confirmed diagnoses recorded during 2025.

Requirements

  1. Return every patient, including patients with no qualifying diagnoses.
  2. Count qualifying diagnosis records and count distinct diagnostic codes per patient.
  3. Return diagnostic codes as a comma-separated, alphabetically ordered list, or NULL when no code matches.
  4. Return the most recent qualifying diagnosis date for each patient, ordered by patient ID.

Apply the date and status conditions without removing patients who have no qualifying records.

Schema

patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_nameVARCHAR(100)Patient display name
patient_diagnoses
ColumnTypeDescription
diagnosis_idPKINTUnique diagnosis record identifier
patient_idINTReferences patients.patient_id
diagnostic_code_idINTReferences diagnostic_codes.diagnostic_code_id
diagnosed_onDATEDate on which the diagnosis was recorded
statusVARCHAR(20)Diagnosis workflow status
diagnostic_codes
ColumnTypeDescription
diagnostic_code_idPKINTUnique diagnostic code identifier
codeVARCHAR(20)Standardized diagnostic code
descriptionVARCHAR(200)Human-readable code description
Tablespatientspatient_diagnosesdiagnostic_codes
Interviewer

Your question is Join Patient Records and Aggregate. Start with the requirements and the three 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.