count(*)vs count(column-name) - 这是更正确吗? [英] count(*) vs count(column-name) - which is more correct?
问题描述
如果您 count(*)
vs count(column-name)
这两个例子?
我有一个倾向总是写 count(*)
,因为它似乎更适合我的思想与它的概念是一个集合函数,如果这是有道理的。
但我不知道如果它在技术上最好,因为我倾向于看到示例代码写的没有 *
更多
code> select customerid,count(*),sum(price)
from items_ordered
group by customerid
有count(*)> 1;
vs。 count(column-name):
SELECT customerid,count(customerid),sum b FROM items_ordered
GROUP BY customerid
HAVING count(customerid)> 1;
-
COUNT(*)
对所有行计数 -
COUNT(列)
/ li>
-
COUNT(1)
是相同的COUNT(*)
,因为1是非空的表达式
您对 COUNT(*)
或 COUNT(column)
的使用应基于所需的输出仅。
Does it make a difference if you do count(*)
vs count(column-name)
as in these two examples?
I have a tendency to always write count(*)
because it seems to fit better in my mind with the notion of it being an aggregate function, if that makes sense.
But I'm not sure if it's technically best as I tend to see example code written without the *
more often than not.
count(*):
select customerid, count(*), sum(price)
from items_ordered
group by customerid
having count(*) > 1;
vs. count(column-name):
SELECT customerid, count(customerid), sum(price)
FROM items_ordered
GROUP BY customerid
HAVING count(customerid) > 1;
COUNT(*)
counts all rowsCOUNT(column)
counts non-NULLs onlyCOUNT(1)
is the same asCOUNT(*)
because 1 is a non-null expressions
Your use of COUNT(*)
or COUNT(column)
should be based on the desired output only.
这篇关于count(*)vs count(column-name) - 这是更正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!