Provider Analytics Path · Mission 15 of 25Medium

Patient age at admission

Use date arithmetic with mixed date formats and CASE WHEN for age bucketing

Back to Provider Analytics

The Brief

Dr. Linda NguyenChief Medical Officerclinical-analytics

I need a breakdown of encounter volume by patient age group at time of admission: 0-17, 18-39, 40-64, 65+. Calculate age from date of birth and admit date — don't use a static age field. Be careful — I've heard some DOB values are stored in a different date format than others.

You'll practice

Date arithmeticCASE bucketsFormat handling

Tables & columns available

fact_encountersfact10 columns
ColumnTypeKey
encounter_idINTPK
patient_idINTFK → dim_patients
provider_idINTFK → dim_providers
department_idINTFK → dim_departments
admit_dateTEXT
discharge_dateTEXT
diagnosis_codeTEXT
diagnosis_descriptionTEXT
encounter_typeTEXT
discharge_dispositionTEXT
dim_patientsdim9 columns
ColumnTypeKey
patient_idINTPK
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
genderTEXT
insurance_typeTEXT
zip_codeTEXT
primary_languageTEXT
is_deceasedINT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Compute age AT the time of admission — not today's age. Watch out: some DOBs are in a different format than the rest

Hint 2

Difference two dates to get years, bucket the result with a conditional expression, then GROUP BY the bucket

Hint 3

`CASE WHEN age < 18 THEN '0-17' WHEN age < ___ THEN '18-39' WHEN age < ___ THEN '40-64' ELSE ___ END AS age_group` — GROUP BY age_group, COUNT(*) each