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

每类试卷得分前3名

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

select 
    tt.tid
  , tt.uid
  , tt.ranking
from (
    select 
      t1.tag as tid
    , t2.uid as uid
    # 如果两人最大分数相同,选择最小分数大者,如果还相同,选择uid大者
    , row_number() over(partition by t1.tag order by max(t2.score) desc, min(t2.score) desc, t2.uid desc ) as ranking
    from examination_info t1
    left join exam_record t2
        on t2.exam_id = t1.exam_id
    group by t1.tag, t2.uid
   ) tt
where tt.ranking <= 3  # 前三名
/*SQL*/;

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 12:05
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 11:45
你不要过来啊啊啊啊啊啊啊
码农索隆:对面:“今天你不面也得面”
点赞 评论 收藏
分享
水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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