description |
---|
Evaluates a list of conditions and returns the first resulting true expression. If a true expression is not found, will return the ELSE statement, if present, or else will return NULL. |
- expression: A valid SQL expression, typically, a column name.
- condition: A boolean expression. If
condition
is true, then returnresult
. - result: A valid SQL expression.
Examples
{% code title="CASE example" %}
SELECT
CASE categories
WHEN 'Restaurants' THEN 'food'
WHEN 'Hotels' THEN 'travel'
ELSE 'no result'
END
FROM table-name
-- food
{% endcode %}
- condition: A boolean expression. If
expression=condition
is true, then returnresult
. - result: A valid SQL expression.
Examples
{% code title="CASE example" %}
SELECT
CASE
WHEN categories='Restaurants' THEN 'food'
WHEN categories='Hotels' THEN 'travel'
ELSE 'no result'
END
FROM table-name
-- food
{% endcode %}