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

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

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

  1. 创建子表t,记录每个归一化的成绩
  • 最大值:max(score)over(partition by exam_id)
  • 最小值:min(score)over(partition by exam_id)
  • 归一化之后的新值:if(最大=最小,原值,归一化的值)
  • 条件:成绩不为空 and 难度困难,where...and
    with t as (
    select 
      uid,
      exam_id,
      if(max(score) over(partition by exam_id) = min(score) over(partition by exam_id),
         score,
         (score-min(score) over(partition by exam_id))/(max(score) over(partition by exam_id)-min(score) over(partition by exam_id))
         ) as new_score
    from exam_record 
    where score is not null
    and exam_id in(
      select 
          distinct exam_id 
      from examination_info 
      where difficulty = 'hard' 
      ) 
    )
  1. 从t表中选择要的值
  • 平均值:avg()
  • 保留小数:round()
  • 分组:group by uid,exam_id
  • 排序:order by exam_id,avg_new_score desc
  • 无序列表内容
    select 
      uid,
      exam_id,
      round(avg(new_score)*100,0) as avg_new_score
    from t
    group by uid,exam_id
    order by exam_id,avg_new_score desc
  1. 合并
    with t as (
    select 
     uid,
     exam_id,
     if(max(score) over(partition by exam_id) = min(score) over(partition by exam_id),
        score,
        (score-min(score) over(partition by exam_id))/(max(score) over(partition by exam_id)-min(score) over(partition by exam_id))
        ) as new_score
    from exam_record 
    where score is not null
    and exam_id in(
     select 
         distinct exam_id 
     from examination_info 
     where difficulty = 'hard' 
     ) 
    )
    select 
     uid,
     exam_id,
     round(avg(new_score)*100,0) as avg_new_score
    from t
    group by uid,exam_id
    order by exam_id,avg_new_score desc
全部评论

相关推荐

不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务