数据库如下:
序号 姓名 成绩
1 张三 89
2 李四 76
3 王五 85
4 赵六 66
5 某某 45
现在要求汇总如下:90分以上 85-90 70-85 60-70 60以下
0 2 1 1 1
序号 姓名 成绩
1 张三 89
2 李四 76
3 王五 85
4 赵六 66
5 某某 45
现在要求汇总如下:90分以上 85-90 70-85 60-70 60以下
0 2 1 1 1
sum(case when 成绩<=90 and 成绩>80 then 1 else 0 end)[90分以上],
from
biao
sum(case when 成绩>=90 then 1 else 0 end) as [90分以上],
sum(case when 成绩>=85 and 成绩<90 then 1 else 0 end) as [85-90],
sum(case when 成绩>=70 and 成绩<85 then 1 else 0 end) as [70-85],
sum(case when 成绩>=60 and 成绩<70 then 1 else 0 end) as [60-70],
sum(case when 成绩<60 then 1 else 0 end) as [60以下]
from test
sum(case when 成绩<=90 and 成绩>85 then 1 else 0 end)[85-90]
--...同上
from
biao
insert into #table1
select 1,'张三',89 union
select 2,'李四',64 union
select 3,'五',85 union
select 4,'赵六',66 union
select 5,'某某',45 select * from #table1select (select count(*) from #table1 where c>=90),
(select count(*) from #table1 where 90 > c and c>=85 ) ,
(select count(*) from #table1 where 85>c and c>=70) ,
(select count(*) from #table1 where 70>c and c > 60) ,
(select count(*) from #table1 where c< 60)
不好意思,可能是我给分的时候你回的贴子