Healthcare 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 Healthcare 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 available

fact_encountersdim_patients

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