Use CASE WHEN to bucket values, filter bad data, and join multiple tables
I need ED throughput broken into wait time buckets: under 30 minutes, 30 to 60, 60 to 120, and over 120. Count encounters in each bucket. But first — filter out any wait times over 480 minutes. Those have to be data entry errors. I need real numbers for the nursing leadership meeting.
Each hint you reveal reduces the XP you can earn. Try the query first.
Three tables connect here: the metric, the encounter, the department. Remember from Mission 4 — the ED is split across three department names
Bucket the numeric wait with a conditional expression in the SELECT, then GROUP BY that bucket. Drop the impossible outliers before bucketing
`CASE WHEN metric_value < 30 THEN 'Under 30 min' WHEN metric_value < ___ THEN '30-60 min' WHEN metric_value < ___ THEN '60-120 min' ELSE ___ END AS wait_bucket` — filter with `metric_value <= ___ AND department_name IN (___, ___, ___)`