``create table conditiontest(a int) distributed by hash(a);``
``insert into conditiontest values (1),(2),(3);``
``````SELECT * FROM conditiontest;
+---+
| a |
+---+
| 2 |
| 1 |
| 3 |``````

## CASE

``````CASE expression
WHEN value THEN result
[ WHEN ... ]
[ ELSE result ]
END   ``````
• 命令说明：简单`CASE`表达式会从左到右依次查找`value`，直到找到和`expression`相等的`value`，并返回对应的`result`结果；如果没有找到相等的`value`，则返回`ELSE`语句后的`result`结果。
• 示例：
``````SELECT a,
CASE a
WHEN 1 THEN 'one'
WHEN 2 THEN 'two'
ELSE 'three'
END as caseresult
FROM conditiontest;
+---+------------+
| a | caseresult |
+---+------------+
| 2 | two        |
| 1 | one        |
| 3 | three      |``````
``````CASE
WHEN condition THEN result
[ WHEN ... ]
[ ELSE result ]
END``````
• 命令说明：高级`CASE`表达式会从左到右依次计算`condition`，直到第一个为`TRUE``condition`，并返回对应的`result`结果；如果没有找到为`TRUE``condition`，则返回`ELSE`语句后的`result`结果。
• 示例：
``````SELECT a,
CASE a
WHEN a=1 THEN 'one1'
WHEN a=2 THEN 'two2'
ELSE 'three3'
END as caseresult
FROM conditiontest;
+---+------------+
| a | caseresult |
+---+------------+
| 1 | one1       |
| 3 | three3     |
| 2 | three3     |``````

## IF

``if(condition, true_value)``
• 命令说明：如果`condition``true`，结果返回`true_value`；否则返回`null`
• 示例：
``````SELECT IF((2+3)>4,5);
+-------+
| _col0 |
+-------+
|     5 |``````
``if(condition, true_value, false_value)``
• 命令说明：如果`condition``true`，结果返回`true_value`；否则结果返回`false_value`
• 示例：
``````SELECT IF((2+3)<5,5,6);
+-------+
| _col0 |
+-------+
|     6 |``````

## IFNULL

``IFNULL(expr1,expr2)``
• 命令说明：如果`expr1`结果不为空，则返回`expr1`的值；否则返回`expr2`的值。
• 示例：
``````SELECT IFNULL(NULL,2);
+-------+
| _col0 |
+-------+
|     2 |
SELECT IFNULL(1,0);
+-------+
| _col0 |
+-------+
|     1 |``````

## NULLIF

``NULLIF(expr1,expr2)``
• 命令说明：如果`expr1``expr2`值相等，结果返回`null`；否则结果返回`expr1`的值。
• 示例：
``````SELECT NULLIF (2,1);
+-------+
| _col0 |
+-------+
|     2 |
SELECT NULLIF (2,2);
+-------+
| _col0 |
+-------+
| NULL  |``````