select c.c_id,c.c_name, Max(sc.s_score) '最高分', MIN(sc.s_score) '最低分', AVG(sc.s_score) '平均分', SUM(case when sc.s_score>=60 then 1 else 0 end)/count(sc.s_id) "及格率", SUM(case when sc.s_score>=70 and sc.s_score<80 then 1 else 0 end)/count(sc.s_id) "中等率", SUM(case when sc.s_score>=80 and sc.s_score<90 then 1 else 0 end)/count(sc.s_id) "优良率", SUM(case when sc.s_score>=90 then 1 else 0 end)/count(sc.s_id) "优秀率" from score sc inner join course c on sc.c_id=c.c_id group by c.c_id
结果: