不用写存储过程,直接一个查询语句就可以了
Access写法
select 班级名称, sum(iif(分数>=90,1,0)) as A, sum(iif(分数>=80 and 分数<90,1,0)) as B, sum(iif(分数>=70 and 分数<80,1,0)) as C, sum(iif(分数>=60 and 分数<70,1,0)) as D, sum(iif(分数<60,1,0)) as E from 成绩表 group by 班级名称
Sql2000写法
select 班级名称, sum(case when 分数>=90 then 1 else 0 end) as A, sum(case when 分数>=80 and 分数<90 then 1 else 0 end) as B, sum(case when 分数>=70 and 分数<80 then 1 else 0 end) as C, sum(case when 分数>=60 and 分数<70 then 1 else 0 end) as D, sum(case when 分数<60 then 1 else 0 end) as E from 成绩表 group by 班级名称
A 为 90分以上的人数,B 为 80~90分的人数,C 为 70~80分的人数,D 为 60~70分的人数,E 为 60分一下的人数