题解 | #每类试卷得分前3名#

每类试卷得分前3名

http://www.nowcoder.com/practice/255aa1863fe14aa88694c09ebbc1dbca

重点是理解题意

将每类试卷的最大值、最小值查出来,并根据题型、uid进行分组

这里可以进行连续排列:

partition by tag order by max_score desc,min_score desc,uid desc

(如果两人最大分数相同,选择最小分数大者,如果还相同,选择uid大者)

select  tag as tid,uid, rk1 as ranking from 
(select *, rank()over(partition by tag order by max_score desc,min_score desc,uid desc) as rk1 from 
(select tag,es.uid,max(score) as max_score,min(score) as min_score
 from examination_info ex
left join exam_record es
on ex.exam_id=es.exam_id
group by tag,es.uid ) e
)a
where rk1<=3
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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