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

每类试卷得分前3名

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

with tmp as
(
select 
distinct 
tag tid,
uid,
-- score,
max(score) over(partition by tag,uid ) max_score,
min(score) over(partition by tag,uid ) min_score
from 
exam_record a left join
examination_info b
on a.exam_id=b.exam_id
where score is not null
)

select 
*
from 
(
select 
tid,
uid,
row_number() over (partition by tid order by max_score desc,min_score desc,uid desc) ranking
from
tmp
) a
where a.ranking <=3

知识点

使用窗口函数之后取TOPN,要用子查询,固定的写法

select *
       from (select *,row_number() over(partition by 姓名 order by 成绩 desc)as ranking
                    from 各科成绩表) as a
       where ranking <= 2;
全部评论

相关推荐

快手真的是我目前面试到的最有压力的了,全程一个多小时,不断的问我简历上的项目,以及当时的做法想法思路,问到我答不出来为止,我就很难判断我的回答是不是他想要听到的,非常折磨。。。。
在吵架的熊熊很甜美:我昨晚面阿里巴巴某事业群的时候一模一样。他揪着问很细很细的点,我只能按照自己的想法回答,他一点点反馈都没有,我不知道说的对不对,越说越心虚,我说不下去之后,他居然在那笑…好讨厌这样的面试…
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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