Use CASE WHEN for rate calculation, LOWER() for normalization, and multi-table JOINs
Calculate the 30-day readmission rate by insurance type. Use the readmission_flag in quality metrics. Normalize insurance type so 'Medicare' and 'medicare' are grouped together. Show insurance type, total encounters with a readmission metric, readmissions, and readmission rate as a percentage rounded to 1 decimal.
Each hint you reveal reduces the XP you can earn. Try the query first.
Three tables chain together: the metric links to the encounter, which links to the patient. Filter the metric_type upfront
Compute two quantities per group — totals and readmissions — and divide. Normalize the grouping key so casing doesn't split rows
`SELECT LOWER(p.insurance_type) AS insurance_type, COUNT(*) AS total_encounters, SUM(CASE WHEN qm.metric_value = 1 THEN ___ ELSE ___ END) AS readmissions, ROUND(100.0 * SUM(CASE WHEN qm.metric_value = 1 THEN 1 ELSE 0 END) / ___, 1) AS readmission_rate ... GROUP BY LOWER(___)`