ifnull语句
IFNULL 语句
SELECT IFNULL(value1,value2) AS status; 当value1为null时,返回结果为value2 当value1非null时,返回结果为value1
例1:
SELECT IFNULL('非空','空') AS status; 结果为: 非空 SELECT IFNULL(null,'空') AS status; 结果为: 空
测试结果:
mysql> SELECT IFNULL(null,'空') AS status; +--------+ | status | +--------+ | 空 | +--------+ 1 row in set
mysql> SELECT IFNULL('非空','空') AS status; +--------+ | status | +--------+ | 非空 | +--------+ 1 row in set
mysql>