CASE expression

Used as an expression. If WHEN is true it will then perform the corresponding THEN expression.

You can use CASE-WHEN-THEN as an expression or in an expression. With this form, the WHEN-THEN clause can be repeated any number of times. Each WHEN expression is a Boolean that must be true in order to perform the corresponding THEN expression. However, the representation is order-dependent so that the first WHEN expression that evaluates to true at runtime is the only one that performs its corresponding THEN expression. If none of the WHEN expressions are true, the ELSE expression is performed, if present.

CASE { WHEN condition THEN expression } [...] [ELSE expression] END [CASE]

The following is an example of a SELECT clause using a CASE expression:

SELECT
CASE
WHEN price>2000.00 THEN 4
WHEN price>1000.00 THEN 3
WHEN price>500.00 THEN 2
ELSE 1
END