mysql當查詢某字段結果為空並賦值


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用法

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM