名称 | 描述 |
---|---|
CASE | Case 操作 |
IF() | If/else 结构 |
IFNULL() | Null if/else 结构 |
NULLIF() | Return NULL if expr1 = expr2 |
CASE value WHEN compare_value THEN result [WHEN compare_value THEN result ...] [ELSE result] END
CASE WHEN condition THEN result [WHEN condition THEN result ...] [ELSE result] END
SELECT CASE 1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'more' END;
SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
SELECT CASE BINARY 'B' WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
SELECT IF(1>2,2,3);
SELECT IF(1<2,'yes','no');
SELECT IF(STRCMP('test','test1'),'no','yes');
SELECT IFNULL(1,0);
SELECT IFNULL(NULL,10);
SELECT IFNULL(1/0,10);
SELECT IFNULL(1/0,'yes');
SELECT NULLIF(1,1);
SELECT NULLIF(1,2);