CASE
mysql> SELECT CASE 1 WHEN 1 THEN 'one' -> WHEN 2 THEN 'two' ELSE 'more' END; -> 'one' mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END; -> 'true' mysql> SELECT CASE BINARY 'B' -> WHEN 'a' THEN 1 WHEN 'b' THEN 2 END; -> NULL
IFNULL
mysql> SELECT IFNULL("TEST", 'OK'); +----------------------+ | IFNULL("TEST", 'OK') | +----------------------+ | TEST | +----------------------+ 1 row in set (0.00 sec) mysql> SELECT IFNULL(NULL, 'OK'); +--------------------+ | IFNULL(NULL, 'OK') | +--------------------+ | OK | +--------------------+ 1 row in set (0.00 sec)
NULLIF()
IF
mysql> SELECT IFNULL("TEST", 'OK'); +----------------------+ | IFNULL("TEST", 'OK') | +----------------------+ | TEST | +----------------------+ 1 row in set (0.00 sec) mysql> SELECT IFNULL(NULL, 'OK'); +--------------------+ | IFNULL(NULL, 'OK') | +--------------------+ | OK | +--------------------+ 1 row in set (0.00 sec)
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。