Allows you to write CASE operators more compactly in queries.
Syntax
multiIf(cond_1, then_1, cond_2, then_2, ..., else)
Parameters:
cond_N— Condition for the function to return then_N.then_N— The result returned when the function is executed.else— The result returned by the function if no condition is satisfied.This function accepts 2N+1 parameters.
Return value The function returns according to the condition Returns one of the values then_N or else. elsecond_N
Example
CREATE TABLE IF NOT EXISTS test.functionMultiIf (id UInt8, left Nullable(UInt8), right Nullable(UInt8)) ENGINE=CnchMergeTree ORDER BY id; INSERT INTO test.functionMultiIf VALUES (1,NULL,4),(2,1,3),(3,2,2),(4,3,1),(5,4,NULL); SELECTleft,right, multiIf(left < right, 'left is smaller', left > right, 'left is greater', left = right, 'Both equal', 'Null value') AS resultFROM test.functionMultiIf
┌─left─┬─right─┬─result──────────┐ │ ᴺᵁᴸᴸ │ 4 │ Null value │ │ 1 │ 3 │ left is smaller │ │ 2 │ 2 │ Both equal │ │ 3 │ 1 │ left is greater │ │ 4 │ ᴺᵁᴸᴸ │ Null value │ └──────┴───────┴─────────────────┘