Mysql IFNULL函数中有两个参数,如果ifnull第一个参数不为null,就会显示出查询的结果,如果第一个参数为null,则会返回第二个参数的字符串,
但是查询结果不为空时,ifnull才会生效,
- 表数据:
- 查不到记录的sql:
select ifnull(store_id, '空') as storeId from area_table where area = 'berserk';
查询结果:
- 能查到记录的sql:
select ifnull(store_id, '空') as storeId from area_table where area = 'archer';
查询结果: