一、case语句
当当前字段为空,查询结果返回“none”,并且统计出现频率
select case when 字段 is null then 'none' else 字段 end as 字段, count(1) as counts from 表 group by 字段;
当当前字段为空字符串,查询结果返回“none”,并且统计出现频率
select case when 字段= '' then 'none' else 字段 end as 字段, count(1) as counts from 表 group by 字段;
当当前字段为空,查询结果返回“none”
select case when 字段 is null then 'none' else 字段 end as 字段 from 表;
当当前字段为空字符,查询结果返回“none”
select case when 字段= '' then 'none' else 字段 end as 字段 from 表;
二、isnull,ifnull,nullif的用法
1、IFNULL(expr1,expr2)的用法:
假如expr1 不为 NULL,则 IFNULL() 的返回值为 expr1;
否则其返回值为 expr2。IFNULL()的返回值是数字或是字符串,具体情况取决于其所使用的语境。
IFNULL( c.LEVEL, '小白键盘手' ) AS LEVEL
2、NULLIF(expr1,expr2) 的用法:
如果expr1 = expr2 成立,那么返回值为NULL,否则返回值为 expr1。
3、isnull(expr) 的用法:
如expr 为null,那么isnull() 的返回值为 1,否则返回值为 0。