题解 | #考试分数(五)#

考试分数(五)

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

WITH T AS
(
    select job
            , sum(1) max_1
    from grade
    group by job
    order by job
)
SELECT 
    G.id
    ,G.job
    ,G.score
    ,G.t_rank 
FROM (SELECT 
    *
    ,ROW_NUMBER() OVER (PARTITION BY job ORDER BY score DESC) t_rank 
FROM grade) G
LEFT JOIN T ON G.job = T.job
WHERE G.t_rank IN (floor((T.max_1+1)/2),floor((T.max_1+2)/2))
ORDER BY G.id
;

# WITH T AS
# (
#     select job
#             ,floor((sum(1)+1)/2) as start
#             ,floor((sum(1)+2)/2) as end
#             , sum(1) max_1
#     from grade
#     group by job
#     order by job
# )
# SELECT *
# FROM T
# ;

全部评论

相关推荐

10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
我见java多妩媚:大外包
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务