distinct與NULL在count的注意事項

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作爲一個值。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章