Use date arithmetic with mixed date formats and CASE WHEN for age bucketing
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.
Each hint you reveal reduces the XP you can earn. Try the query first.
Compute age AT the time of admission — not today's age. Watch out: some DOBs are in a different format than the rest
Difference two dates to get years, bucket the result with a conditional expression, then GROUP BY the bucket
`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