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