CASE
Returns different values depending on conditions — “if… then… else” in SQL.
Syntax
CASE WHEN <condition> THEN <result> … ELSE <otherwise> END
CASE <expression> WHEN <value> THEN <result> … ELSE <otherwise> END
It's an expression rather than a function, but you write it in the same places as functions. Conditions are checked from top to bottom, and the first true one wins; if none matches, ELSE is used, and without it — NULL. The second form is shorter: it compares one expression against a list of values.