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

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

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

select 
uid,exam_id,
-- case when round(sum(guiyi)/count(case when guiyi<>0 then guiyi else null end),0) is not null 
-- then round(sum(guiyi)/count(case when guiyi<>'0' then guiyi else null end),0)
-- else 0 end as avg_new_score
round(avg(guiyi),0) avg_new_score
from(
	select 
	uid,exam_id,
	case when cnt<>1 then (score-min_score)/(max_score-min_score)*100 
	else score end as guiyi
	-- case when format((score-min_score)/(max_score-min_score)*score,0)<>0 then format((score-min_score)/(max_score-min_score)*score,0) else score end avg_new_score
	from (
		select 
		a.uid,a.exam_id,a.score,
		min(score) over (partition by exam_id) min_score,
		max(score) over (partition by exam_id) max_score,
		count(score) over (partition by exam_id) cnt
		from exam_record a left join examination_info b
		on a.exam_id =b.exam_id 
		where b.difficulty='hard'
		and score is not null
		-- order by exam_id,uid
	) d
	-- order by exam_id,uid
	-- where (score-min_score)/(max_score-min_score)*score<>0
)e
group by uid,exam_id
order by exam_id asc,avg_new_score desc

全部评论

相关推荐

11-01 20:03
已编辑
门头沟学院 算法工程师
Amazarashi66:这种也是幸存者偏差了,拿不到这个价的才是大多数
点赞 评论 收藏
分享
10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务