What it does:
This query calculates the medication adherence rate across different age groups, grouped by decades (e.g., 10s, 20s, 30s).
SQL Breakdown:
FLOOR(age / 10) * 10 AS age_group: Groups patients by decade of life (e.g., 21 becomes 20).
COUNT(*) AS patients: Counts the total number of patients in each age group.
COUNT(*) FILTER (WHERE adherence = 'ADHERENT') * 1.0 / COUNT(*) AS adherence_rate: Calculates the adherence rate per age group.
GROUP BY age_group: Ensures aggregation by age decade.
ORDER BY age_group: Sorts results from youngest to oldest.
Output Summary:
Lowest adherence is in the 20s (8%) and 30s (16%) age groups.
Adherence improves significantly after age 50.
Highest adherence appears in the 70s (55%), 80s (55%), and a tiny sample at age 100 (67%).
Why this matters:
This analysis shows that younger patients are significantly less adherent to medication regimens than older patients. This could help inform age-targeted interventions, such as educational campaigns or follow-up protocols for younger demographics.
Note: This dataset is synthetic and used strictly for educational purposes. It does not reflect real patient data.