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

考试分数(五)

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

先准备好两个表
一个是上一题的 两个中位数的位置在哪里
一个是带排名的表
两个表用where连接一下就好了

select g.id,
    g.job,
    g.score,
    g.t_rank
from
    (select id,
        job,
        score,
        row_number() over(partition by job order by score desc) as t_rank
    from grade) g,
    (select job,
        (case when count(1)%2=1 then round((count(1)+1)/2) else round(count(1)/2) end) start,
        (case when count(1)%2=1 then round((count(1)+1)/2) else round(count(1)/2)+1 end) end
    from grade
    group by job
    order by job) tmp
where g.job = tmp.job and (g.t_rank=tmp.start or g.t_rank=tmp.end)
order by g.id, g.t_rank desc;
全部评论

相关推荐

Cherrycola01:0实习 0项目 约等于啥也没有啊 哥们儿这简历认真的吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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