查询各科成绩最高分、最低分和平均分:以如下形式显示:课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率

– 及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90
SELECT c.c_id 课程ID,c.c_name 课程NAME,MAX(s.s_score) 最高分,MIN(s.s_score) 最低分,AVG(s.s_score) 平均分,
a.vv 及格率,b.cc 中等率,c.ww 优良率,d.aa 优秀率
FROM score s,course c,
(SELECT a.cou/b.co vv FROM(SELECT c_id ,COUNT(c_id) cou FROM score WHERE s_score >60 GROUP BY c_id) a,(SELECT c_id ,COUNT(c_id) co FROM score GROUP BY c_id) b WHERE a.c_id=b.c_id) a,
(SELECT a.cou/b.co cc FROM(SELECT c_id ,COUNT(c_id) cou FROM score WHERE s_score >=70 AND s_score <80 GROUP BY c_id) a,(SELECT c_id ,COUNT(c_id) co FROM score GROUP BY c_id) b WHERE a.c_id=b.c_id) b,
(SELECT a.cou/b.co ww FROM(SELECT c_id ,COUNT(c_id) cou FROM score WHERE s_score >=80 AND s_score <90 GROUP BY c_id) a,(SELECT c_id ,COUNT(c_id) co FROM score GROUP BY c_id) b WHERE a.c_id=b.c_id) c,
(SELECT a.cou/b.co aa FROM(SELECT c_id ,COUNT(c_id) cou FROM score WHERE s_score >90 GROUP BY c_id) a,(SELECT c_id ,COUNT(c_id) co FROM score GROUP BY c_id) b WHERE a.c_id=b.c_id) d
WHERE s.c_id=c.c_id GROUP BY s.c_id

你可能感兴趣的:(查询各科成绩最高分、最低分和平均分:以如下形式显示:课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率)