Why does COUNT(score) count only two of three reviews?

COUNT(*) counts rows. COUNT(expression) counts rows in which that expression has a non-NULL value.

SQLite example and interpretation

A blank scorecard is still a submission. A zero is a recorded score and belongs in the scored denominator.

WITH reviews(score) AS (VALUES(0),(NULL),(4)) SELECT count(*),count(score) FROM reviews;

Result [[3, 2]]

中文

有三条审核记录,为什么 COUNT(score) 只算两条?

COUNT(*) 计行,COUNT(表达式) 只计表达式非 NULL 的行。

SQLite 示例与适用条件

把提交箱和评分箱分开看:一张空白评分单仍是一次提交。零分已经打过分,不能当作缺评。

WITH reviews(score) AS (VALUES(0),(NULL),(4)) SELECT count(*),count(score) FROM reviews;

结果 [[3, 2]]

References / 参考来源

Keep reading / 继续阅读