count(*)和count(Name)之间的差异 [英] difference between count(*) and count(Name)

查看:100
本文介绍了count(*)和count(Name)之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算一个表中特定ID的行数。



而不是写SELECT COUNT(*)FROM TABLE我应该写SELECT COUNT(姓名)FROM TABLE ???



然后告诉我更好的表现哪个适合?

i want to count number of rows in a table for a particular ID.

Instead of writing SELECT COUNT(*) FROM TABLE shall i write SELECT COUNT(Name) FROM TABLE???

then tell me for better performance which is suitable??

推荐答案

而不是写作

从表格中选择计数(*)





从表中选择计数(名称)

它只计算Name列中的值。



第二个是性能更好。
Instead of writing
Select count(*) from table
It will count null values and values


Select count(name) from table
It will count only the values present in Name column.

Second one is the better performance.


结果可能会根据相关表格中的列值而有所不同。



COUNT(*) - 检索表中所有可用行的计数。

COUNT(名称) - 仅检索所选表格中可用的非空值的数量。



希望这对您有所帮助。
Results can be vary according to the column values available in the relevant table.

COUNT(*) - retrieve the count of all the rows available in the table.
COUNT(Name) - retrieve only the count of non-null values available in the selected table.

Hope this will help you.


基本上,如果你执行 COUNT(*),它会返回整行数据,然后将其计为1,< b>然后转到下一行并将其计为2,依此类推。



A COUNT(名称)将计算第1行的名称,即名称对于第2行,依此类推。



你在 COUNT()函数中输入的任何内容都是一样的。



但是,如果您使用列名作为参数, COUNT 将返回<$ c的计数$ c> NON-NULL 该列的值。
Basically, if you do a COUNT(*), it returns an entire row of data and then counts it as 1, then goes to the next row and counts that as 2, and so on.

A COUNT(Name) would "count" a "Name" for row 1, a "Name" for row 2, and so on.

Anything you put in the COUNT() function work the same.

However, if you use a column name as the parameter, COUNT will return a count of NON-NULL values of that column.


这篇关于count(*)和count(Name)之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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