SQL · Pattern 3 — Built-in Functions
CASE WHEN
`CASE WHEN ...
Source data — Pattern 3: Built-in Functions
All queries run against the shared employees table (see schema.sql). This pattern needs two columns not used before: hire_date (topic 17) and bonus, nullable (topics 19–20).

What it does
CASE WHEN ... THEN ... ELSE ... END is SQL's if/else — it evaluates conditions top to bottom and returns the result tied to the first one that matches, falling through to ELSE if none do. It's an expression, so it can sit anywhere a column would.
Problem
Categorize salaries as High, Medium, or Low.
SELECT first_name,
salary,
CASE
WHEN salary >= 100000 THEN 'High'
WHEN salary >= 60000 THEN 'Medium'
ELSE 'Low'
END AS salary_band
FROM employees;
Result
