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

每类试卷得分前3名

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

#1.以作答表为主表进行连接两张表,找出每类试卷每类用户(group by tag, uid)的最大分数和最小分数,在后面加两列
with c as (select b.tag,a.uid,max(a.score) max_score,min(a.score) min_score
from exam_record a left join examination_info b on a.exam_id=b.exam_id
group by b.tag,a.uid),
#2.按照规则加一列ranking!
    row_number() over(partition by tag order by c.max_score desc, c.min_score desc,uid desc) ranking

#完整:
with c as (select b.tag,a.uid,max(a.score) max_score,min(a.score) min_score
from exam_record a left join examination_info b on a.exam_id=b.exam_id
group by b.tag,a.uid),
    d as (select c.tag,c.uid,c.max_score,c.min_score,
row_number() over(partition by tag order by c.max_score desc, c.min_score desc,uid desc) ranking
from c)
select tag,uid, ranking 
from d 
where ranking <=3;

#sql#
全部评论

相关推荐

05-30 18:54
武汉商学院 Java
啥都不会1:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
头像
05-16 11:16
已编辑
东华理工大学 Java
牛客737698141号:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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