SQL语句的问题数据库查询统计的问题

来源:百度知道 编辑:UC知道 时间:2024/06/18 23:43:50
有表
table
id name
1 a
2 b
3 c
4 c
5 b
6 a
7 a
。。。。。共几千条数据
要统计出表中name等于a、b、c、d的各有多少?
select count(name)as A from table where name=a
这样只能统计出等于A的人数是多少
怎么写才能一条语句统计出a、b、c、d分别有多少人?

select count(name)as A from table
group by name

Select name,count(name) as num
From 表名
Group by name Having count(name)>0 Order by count(name) desc
显示全部 按重复次数查询

select name,count(name)as '人数' from table group by name

只要根据 name 来分组 基本就OK了

count(name) table 表中任何一个字段也可以 *,1

Select name,count(name) as num
From table
Group by name

select [name],count([name]) as A from [table] group by [name]

select name,count(*) cnt from table where name in(a,b,c,d) group by name;