14题中还要求显示课程name,需要再关联course表:
select s2.cid "课程ID",s1.cname "课程名称", s2.crcount "选修人数",s2.mx "最高分",s2.mn "最低分",s2.avgs "平均分",s2.jg "及格率",s2.zd "中等率",s2.yl "优良率",s2.yx "优秀率"
from course s1 ,(select cid ,count(sid) crcount,max(score) mx,min(score) mn,avg(score) avgs,
sum(case when score>=60 then 1 else 0 end)/count(sid) jg,
sum(case when score>=70 and score<80 then 1 else 0 end)/count(sid) zd,
sum(case when score>=80 and score<90 then 1 else 0 end)/count(sid) yl,
sum(case when score>=90 then 1 else 0 end)/count(sid) yx from sc group by cid) s2
where s1.cid(+)=s2.cid
order by s2.crcount desc,s2.cid;
50道SQL练习题及答案与详细分析网上流传较广的50道SQL训练,奋斗了不知道多久终于写完了。前18道题的难度依次递增,从19题开始的后半部分算是循环练习和额外function的附加练习,难度恢复到普通状态。...