一、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。
到此这篇关于mysql多表联查给null赋值的实现的文章就介绍到这了,更多相关mysql null赋值内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论