题解 | #每类试卷得分前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;
全部评论

相关推荐

牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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