Skip to main content

MULTI_IF

If expr1 is TRUE, MULTI_IF returns expr2. Otherwise, it returns expr3.

Syntax

MULTI_IF( <cond1>, <expr1>, [<cond2>, <expr2> ..], <expr_else>)

Arguments

ArgumentsDescription
<cond_n>The condition for evaluation that can be true, false or NULL.
<expr_n>The expression to return if cond_n is true.
<expr_else>The expression to return if all conditions are false or null.

Return Type

The return type is determined by expr2 and expr3, they must have the lowest common type.

Examples


SELECT MULTI_IF(number=0, true, false) FROM numbers(1);
+-------------------------------+
| MULTI_IF((number = 0), true, false) |
+-------------------------------+
| 1 |
+-------------------------------+
SELECT MULTI_IF(number % 3 = 1, 1, number % 3 = 2, 2, 3) FROM numbers(6);
+---------------------------------------------------+
| MULTI_IF(number % 3 = 1, 1, number % 3 = 2, 2, 3) |
+---------------------------------------------------+
| 3 |
| 1 |
| 2 |
| 3 |
| 1 |
| 2 |
+---------------------------------------------------+