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

每类试卷得分前3名

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

select * from(
    select
    tag as tid,
    uid,
    ROW_NUMBER()OVER(PARTITION BY tag ORDER BY max(score) desc,min(score) desc,uid desc) ranking
from
    examination_info
    join exam_record using (exam_id)
    group by tid,uid) as newform
where newform.ranking <= 3

本题难度是比较大的,必须取row_number()over()来计算每行的排列顺序,用partion by tag来根据标签进行排序,由于是有group by 关键词所以排序规则只能选择uid或者tag,或者min()max()函数去取值。

全部评论

相关推荐

牛客62533758...:华为不卡双非,而是卡院校hhhh
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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