[英]How to get count of first column in select statement
I am trying to replace count (*)
with count(column_name)
我正在尝试用count(column_name)
替换count (*)
count(column_name)
I am able to get the column_name
for some select
statements, but few are very complex and I am not able to find what are the columns returned by that select
statement. 我可以为某些select
语句获取column_name
,但是很少有非常复杂的,并且我无法找到该select
语句返回的列。
Is there a way where I can get count(first_column_name)
when I am not able to find the column name
? 当找不到column name
时,有什么方法可以获取count(first_column_name)
吗?
As told, COUNT(Column_Name)
can be replaced by COUNT(n)
anytime where n = Position of the column in the dataset. 如前所述, COUNT(Column_Name)
可以随时用COUNT(n)
替换,其中n =列在数据集中的位置。
Eg Suppose there is table MyTable
having the below physical structure 例如,假设表MyTable
具有以下物理结构
EmpID|Name|Location
If you want to get a count of EmpID
, use the query 如果要获取EmpID
的计数,请使用查询
SELECT COUNT(1) FROM MyTable
instead of 代替
SELECT COUNT(EmpID) FROM MyTable
If you want a count of locations, use the query, 如果您想统计位置,请使用查询,
SELECT COUNT(3) FROM MyTable
and so on. 等等。
For the dataset SELECT Location, EmpID, Name FROM MyTable
, to get a count of names, you need to use the query 对于数据集SELECT Location, EmpID, Name FROM MyTable
,要获取名称计数,您需要使用查询
SELECT COUNT(3) FROM (SELECT Location, EmpID, Name FROM MyTable)A
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.