gpt4 book ai didi

sql - COUNT(*) 包括空值?

转载 作者:行者123 更新时间:2023-12-04 10:08:47 25 4
gpt4 key购买 nike

MSDN文件指出:

COUNT(*) returns the number of items in a group. This includes NULL values and duplicates.



你怎么能在一个组中有一个空值?谁能解释他们试图提出的观点?

最佳答案

如果你有这张 table

表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

关于sql - COUNT(*) 包括空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40679208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com