子查询;窗口函数row_number over(partition by order by);round;
MySQL面试题18/19
18.查询各科成绩最高分、最低分和平均分:以如下形式显示:课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率,及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90(重要!)
select a.c_id,a.c_name,
MAX(s_score),MIN(s_score),AVG(s_score),
sum(case when b.s_score >= 60 then 1 else 0 end)/count(s_id) as ‘及格率’,
sum(case when b.s_score>80 and b.s_score<90 then 1 else 0 end)/count(s_id) as ‘优良率’,
sum(case when b.s_score>70 and b.s_score<80 then 1 else 0 end)/count(s_id) as ‘中等率’,
sum(case when b.s_score > 90 then 1 else 0 end)/count(s_id) as ‘优秀率’
from
course as a
inner join
score as b
on a.c_id=b.c_id