mysql當查詢某字段結果為空並賦值
阿新 • • 發佈:2017-12-24
bsp 返回 nts mys hive zhang logs isn link
1 代碼
1.1 當當前字段為空,查詢結果返回“none”,並且統計出現頻率
select case when 字段 is null then ‘none‘ else 字段 end as 字段, count(1) as counts from 表 group by 字段;
1.2 當當前字段為空字符串,查詢結果返回“none”,並且統計出現頻率
select case when 字段= ‘‘ then ‘none‘ else 字段 end as 字段, count(1) as counts from 表 group by 字段;
1.3 當當前字段為空,查詢結果返回“none”
select case when 字段 is null then ‘none‘ else 字段 end as 字段 from 表;
1.4 當當前字段為空字符,查詢結果返回“none”
select case when 字段= ‘‘ then ‘none‘ else 字段 end as 字段 from 表;
2 小結
僅作為記錄使用,mysql其它相關命令有isnull,ifnull and nullif。
link: MySql 裏的IFNULL、NULLIF和ISNULL用法
mysql當查詢某字段結果為空並賦值