[英]How can i get number of entries and column name in a unique select?
I have the following table: 我有下表:
IdColumn Name Role Status
1 peter Ope 0
2 peter Adm 1
3 Jon Ope 1
4 Mac Adm 1
5 Jon Adm 0
6 peter Sec 1
What I wanted to get is the column name and number of entries for each one in a single query. 我想要获得的是在单个查询中每个列的名称和条目数。
select Name, Count(*) from table where Status = 1;
Exit example: 退出示例:
---------------
Name | Count()|
---------------
peter| 2 |
Jon | 1 |
Mac | 1 |
---------------
This is a basic group by
query: 这是一个基本的group by
查询group by
:
select Name, Count(*)
from table
where Status = 1
group by Name;
If you are going to use SQL, you should learn the basics. 如果要使用SQL,则应学习基础知识。 group by
and join
are definitely basics of the SQL language. group by
和join
绝对是SQL语言的基础。
Use group by
clause: 使用group by
子句:
select Name, Count(*) from table where Status = 1 group by Name;
^^^
Add group by here
select count(*), Name
from table
where status=1
group by Name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.