If/then/else inside SELECT
Sometimes you need conditional logic inside a query — categorising rows into buckets, replacing missing values, computing different totals based on type. CASE and COALESCE are the workhorses; learn both, plus their cousins NULLIF and GREATEST/LEAST.
The two CASE shapes
Searched CASE evaluates conditions in order: CASE WHEN x >= 100 THEN 'high' ... END. Simple CASE matches a single expression: CASE status WHEN 'P' THEN 'Pending' ... END. Searched is more flexible; simple is briefer when you're matching equality to one column.