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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM