本文主要是介绍count,distinct和group by对null值的操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
distinct 会将所有null视为一项
group by 将所有null值视为一项
count 不会计算null值项,count(null)=0
select count() from (select count() as num from library_books group by stayLibraryHallCode) temp;
输出结果是3229
select COUNT(DISTINCT stayLibraryHallCode) from library_books;
输出结果是3228
原因就是COUNT(DISTINCT stayLibraryHallCode)中有null值项+0,count(*)中null值项+1,所以结果肯定少1
这篇关于count,distinct和group by对null值的操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!