CASE WHEN

CASE WHEN ... THEN ... ELSE ... END is SQL's conditional expression: it returns the value of the first true condition, otherwise the ELSE value, or NULL if there is none. It is used to create categories, flags or buckets in SELECT, ORDER BY or inside an aggregate.

Example

CASE WHEN prix < 10 THEN 'low' WHEN prix < 50 THEN 'medium' ELSE 'high' END

Related concepts

The whole glossary