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

考试分数(五)

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

select
    t1.id,
    t1.job,
    t1.score,
    t1.t_rank
from (
    -- 每个岗位里进行排名打标
    select
        id,
        job,
        score,
        row_number() over(partition by job order by score desc) t_rank
    from grade
) t1
inner join (
    -- 每个岗位的总数的一半
    select 
        job,
        round(count(job) / 2, 1) cn_half
    from grade
    group by job
) t2
on t1.job = t2.job 
where 
case 
    when substr(t2.cn_half,length(t2.cn_half)) then t_rank = round(t2.cn_half + 0.5,0) 
    else t_rank in (round(t2.cn_half,0),round(t2.cn_half + 1,0))
end 
order by t1.id;

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 15:39
希望奇迹发生的布莱克...:真的是 现在卷实习就是没苦硬吃
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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