码迷,mamicode.com
首页 > 其他好文 > 详细

distinct与NULL在count的注意事项

时间:2017-03-26 01:21:07      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:err   适用于   style   alt   count   error   image   images   src   

select * from errorinfo
select count(1) from errorinfo
select distinct info from errorinfo
select count(distinct info) from errorinfo

技术分享

distinct 会将所有NULL合并为一项

count(distinct)会将NULL除去。

 

select count(distinct info), info from errorinfo group by info

 

技术分享

 

null不参与count运算,同样适用于sum, avg。

distinct时,所有null作为一个值。

 

distinct与NULL在count的注意事项

标签:err   适用于   style   alt   count   error   image   images   src   

原文地址:http://www.cnblogs.com/jasonlam/p/6619013.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!