题解 | #对试卷得分做min-max归一化#

对试卷得分做min-max归一化

https://www.nowcoder.com/practice/2b7acdc7d1b9435bac377c1dcb3085d6

-- 1、拿到用户作答高难度试卷的分数、最大值和最小值,作为临时表
/*
select uid,exam_id,score,
    max(score) over(partition by exam_id) as max_sc,
    min(score) over(partition by exam_id) as min_sc
from examination_info join exam_record using(exam_id)
where difficulty='hard'
*/
-- 2、进行标准化的计算
select uid,exam_id,
    round(avg(if(max_sc=min_sc,score,(score-min_sc)/(max_sc-min_sc)*100)),0) avg_new_score
from
    (select uid,exam_id,score,
        max(score) over(partition by exam_id) as max_sc,
        min(score) over(partition by exam_id) as min_sc
    from examination_info join exam_record using(exam_id)
    where difficulty='hard') a
where score is not null
group by exam_id, uid
order by exam_id asc, avg_new_score desc

全部评论

相关推荐

11-05 07:29
贵州大学 Java
点赞 评论 收藏
分享
10-15 09:13
已编辑
天津大学 soc前端设计
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务