COUNT(*) 包括空值? [英] COUNT(*) Includes Null Values?
本文介绍了COUNT(*) 包括空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MSDN 文档说明:
COUNT(*) 返回组中的项目数.这包括 NULL值和重复项.
COUNT(*) returns the number of items in a group. This includes NULL values and duplicates.
你怎么能在一个组中有一个空值?任何人都可以解释他们试图提出的观点吗?
How can you have a null value in a group? Can anyone explain the point they're trying to make?
推荐答案
如果你有这张桌子
表 1:
Field1 Field2 Field3
---------------------------
1 1 1
NULL NULL NULL
2 2 NULL
1 3 1
然后
SELECT COUNT(*), COUNT(Field1), COUNT(Field2), COUNT(DISTINCT Field3)
FROM Table1
输出是:
COUNT(*) = 4; -- count all rows, even null/duplicates
-- count only rows without null values on that field
COUNT(Field1) = COUNT(Field2) = 3
COUNT(Field3) = 2
COUNT(DISTINCT Field3) = 1 -- Ignore duplicates
这篇关于COUNT(*) 包括空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文