以下表数据:
StuNo StuName
1 a
2 b
3 a
4 a
5 b
6 c
要求查询的结果是:
a的个数 b的个数 c的个数
3 2 1
请问sql语句怎么写了??情大家帮忙
select StuName,sum(case StuName when 'a' then 1 else 0 end) as 'a的个数',
sum(case StuName when 'b' then 1 else 0 end) as 'b的个数',
sum(case StuName when 'c' then 1 else 0 end) as 'c的个数' from table
group by StuName
select Count(*) from table group by stuname
select max(num), avg(num), min(num)
from
(
select count(stuname) as num from student group by stuname
) as u
乱写这位