是否可以用sql语句实现分数的分段人数统计

来源:百度知道 编辑:UC知道 时间:2024/06/24 17:33:18
比如说,一个学校内有几千名学生,想用考试成绩对其进行分档统计,10分一个分档,例如0-10分有几个人,10-20分有几个人,直到90-100分有几个人。表名是student_score,字段是 name,id,score。

能否用sql语句实现。
三楼的执行不了啊,在plsql里面。

--结果一条记录的方法
select sum(case when score<10 then 1 else 0 end) as [0-10],
sum(case when score>=10 and score<20 then 1 else 0 end) as [10-20],
sum(case when score>=20 and score<30 then 1 else 0 end) as [20-30],
sum(case when score>=30 and score<40 then 1 else 0 end) as [30-40],
....
from student_score

写存储过程就很容易搞定,用单条SQL语句,我就没有办法了。

我不知道你是怎么弄的,但是三楼回答的是标准答案,而且是通用语言