MySQL多表联查给null赋值的实现 |
一、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; 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赋值内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持! |