题解 | #对试卷得分做min-max归一化#
对试卷得分做min-max归一化
https://www.nowcoder.com/practice/2b7acdc7d1b9435bac377c1dcb3085d6
with data_f_use as ( select uid, exam_id, score from exam_record left join examination_info using (exam_id) where difficulty = 'hard' and score is not null ), score_f_use as ( select uid, exam_id, score, min(score)over(partition by exam_id ) min_score, max(score)over(partition by exam_id) max_score from data_f_use ), new_score_f_use as ( select uid, exam_id, if(min_score = max_score, score ,(score - min_score) * 100 / (max_score - min_score) ) new_score from score_f_use ) select uid, exam_id, round(avg(new_score), 0) avg_new_score from new_score_f_use group by uid, exam_id order by exam_id, avg_new_score desc翻评论后才知道在算new score的时候不要round,我也表示无语