统计每个分数段有多少人的sql怎么写

2025-03-02 11:22:22
推荐回答(2个)
回答1:

select count(case 分数字段 when 100 then 1 end) as [满分],
count(case when 分数字段 between 90 and 99 then 1 end) as[90-99分],
count(case when 分数字段 between 80 and 89 then 1 end) as[80-89分],
count(case when 分数字段 between 70 and 79 then 1 end) as[70-79分],
count(case when 分数字段<70 then 1 end) as[70分以下]
from 学生分数表

回答2:

select count(*) from studentfs where 分数字段=100
union
select count(*) from studentfs where 分数字段<=99 and 分数字段>=90
union
select count(*) from studentfs where 分数字段<=89 and 分数字段>=80
union
select count(*) from studentfs where 分数字段<=79 and 分数字段>=70
union
select count(*) from studentfs where 分数字段<=70