题解 | 考试分数(五)

考试分数(五)

https://www.nowcoder.com/practice/b626ff9e2ad04789954c2132c74c0513

with ranked as(
select id,
       job,
       score,
       row_number() over(partition by job order by score desc) t_rank,
       count(*) over (partition by job) cnts
from grade)
(
    select id,job,score,t_rank
    from ranked 
    where t_rank = CEIL(cnts/2) and cnts%2!=0
)
union all
(
    select id,job,score,t_rank
    from ranked
    where cnts%2=0 and (t_rank = cnts/2 or t_rank = 1+cnts/2 )
)
order by id  

全部评论

相关推荐

昨天 20:41
已编辑
北京交通大学 算法工程师
字节跳动 训练框架研发 (N+2) * (12 + 3) 硕士211
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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