distinct与NULL在count的注意事项

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作为一个值。

 

posted on 2017-03-25 23:32  落忆无痕  阅读(8156)  评论(1编辑  收藏  举报

导航