1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
select class_name, round(avg(chinese), 2) avg_chinese, round(avg(math), 2) avg_math, round(avg(english), 2) avg_english, max(chinese) max_chinese, max(math) max_math, max(english) max_english from student group by class_name
select class_name, max(case when sex = '男' then chinese else null end) mc, max(case when sex = '男' then math else null end) mm, max(case when sex = '男' then english else null end) me, max(case when sex = '女' then chinese else null end) fmc, max(case when sex = '女' then math else null end) fmm, max(case when sex = '女' then english else null end) fme from student group by class_name
select name, id, class_name, sex, round((chinese+math+english)/3.0, 2) avg_score, (chinese+math+english) total_score, greatest(chinese, math, english) highest_score, case greatest(chinese, math, english) when chinese then '语文' when math then '数学' else '英语' end highest_subject, dense_rank() over (partition by class_name order by (chinese+math+english) desc) class_rank, if((chinese+math+english) >= avg(chinese+math+english) over (partition by class_name), '是', '否') above_avg from student order by class_name, class_rank;
select name, id, class_name, (chinese + math + english) total_score, coalesce(lag(chinese + math + english) over (order by chinese + math + english desc) - (chinese + math + english), 0) cha_score from student order by total_score desc;
|