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

什么是窗口函数呢?

窗口函数就是在不改变原表结构的前提下,新建一列。

解题思路分析:

如何判断只有一个分数? 

  • 当min(score)=max(score)那就说明只有一个得分
select uid, exam_id,
round(sum(max_min)/count(max_min),0) avg_new_score
from
(select uid, exam_id, score,
if (min_t=max_t,score,(score-min_t)*100/(max_t-min_t)) max_min
from
(select uid, er.exam_id, score,
max(score) over(partition by er.exam_id) max_t,
min(score) over(partition by er.exam_id) min_t
from exam_record er
left join examination_info using(exam_id)
where difficulty='hard' 
and score is not null)t1)t2
group by uid, exam_id
order by exam_id, avg_new_score desc;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值