为什么count()函数需要参数?

Pro*_*ofK 9 sql-server

count()函数对行进行计数,并且经常用作行count(*).如果我有一个带phoneNo和firstName的表,则count(phoneNumber)返回相同的数字count(*).如果未填充,则每行中始终存在所有列.

Lea*_*ing 20

有一个微妙的区别.

如果指定字段,count(fieldname)将计算该字段具有非空值的记录.count(*)将为您提供总行数.


Mor*_*075 7

另一方面,您可以计算不同的值.count(distinct firstName)可以提供不同的结果作为count(distinct phoneNumber),两者可能与count()不同.