count(*)vs count(column-name) - 这是更正确吗? [英] count(*) vs count(column-name) - which is more correct?

查看:127
本文介绍了count(*)vs count(column-name) - 这是更正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您 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(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;

解决方案

Your use of COUNT(*) or COUNT(column) should be based on the desired output only.

这篇关于count(*)vs count(column-name) - 这是更正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆