select 课程名,
sum(case when 成绩>=85 then 1 else 0 end) as '成绩>=85',
sum(case when 成绩<85 and 成绩>70 then 1 else 0 end) as '成绩>=85',
sum(case when 成绩<60 then 1 else 0 end) as '成绩>=85',
count(*) as '成绩>=85'
from 表
group by 课程名
sum(case when 成绩>=85 then 1 else 0 end) as '成绩>=85',
sum(case when 成绩<85 and 成绩>70 then 1 else 0 end) as '成绩>=85',
sum(case when 成绩<60 then 1 else 0 end) as '成绩>=85',
count(*) as '成绩>=85'
from 表
group by 课程名
学号 课程代码 成绩
1076 mus101a 90.0
989 hum202a 83.0
913 cur201a 75.0
491 itr301a 73.0
627 eng101a 88.0
346 hum201a 63.0
208 eco101a 65.6
9 itr305a 70.0
888 eng102a 91.0
想要的效果图事例 数据不对
代码 〉=60分 〉=70分
acc201a 265 174
acc202a 561 469
acc308a 96 46
acc313a 0 0
adm302a 104 91
adm403a 103 85
cmp410a 161 145
cur201a 634 602
cur301a 34 19
cur302a 238 140
cur304a 0 0
cur305a 210 148
cur309a 202 197514 hum301a 80.0
课程名,
[成绩>=85]=SUM(Case When 成绩>=85 Then 1 Else 0 End) ,
[85>成绩>70]=SUM(Case When 成绩>=70 And 成绩<85 Then 1 Else 0 End) ,
[成绩<60]=SUM(Case When 成绩<60 Then 1 Else 0 End) ,
总人数=Count(1)
from TableName
Group By 课程名
Order By 课程名