首页 > 其他分享> > 查询各科成绩最高分、最低分和平均分:以如下形式显示:课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率--及格为>=60,中等为:70-80,优良为:80-90,优秀为:
查询各科成绩最高分、最低分和平均分:以如下形式显示:课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率--及格为>=60,中等为:70-80,优良为:80-90,优秀为:
作者:互联网
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
结果:
标签:最高分,score,sc,80,id,平均分 来源: https://blog.csdn.net/qq_45740126/article/details/119465187