Guided Notes

CASE, NULLs & Cleaning in SQL

Create categories with CASE, handle NULLs with COALESCE and IS NULL, standardize text, search codes with LIKE, and write conditional counts in one query.

CASE expressions

Slide 1 / 5

CASE creates categories inside a query: SELECT patient_id, CASE WHEN age < 18 THEN 'Child' WHEN age < 65 THEN 'Adult' ELSE 'Senior' END AS age_group FROM ... • Evaluated top to bottom; first match wins. • Use ELSE for 'everything else' (or 'Unknown').

← Dates & Time in Healthcare SQL