首页 > 数据库技术 > 详细

mysql当查询某字段结果为空并赋值

时间:2017-12-24 12:05:06      阅读:527      评论:0      收藏:0      [点我收藏+]

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当查询某字段结果为空并赋值

原文:http://www.cnblogs.com/fanbi/p/8097567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!