oracle:成绩表stu, 有列name,score, 现在要分优秀良好等档次统总分,怎样只用一条查询语句得到所有结果呢

2025-03-10 13:32:36
推荐回答(2个)
回答1:

sum(case when score >85 then score else 0 end ) 优秀
sum(case when score>=75 and score<85 then score else 0 end ) 良好
sum(case when score>=60 and score<75 then score else 0 end ) 及格
sum(case when score<60 then score else 0 end ) 不及格

回答2:

select name 姓名,
case
when score >=85 then '优秀'
when score >=75 and score <85 then '良好'
when score >=60 and score <75 then '及格'
when score <60 then '不及格'
end 成绩
from stu