题解 | #查找在职员工自入职以来的薪水涨幅情况#

考试分数(五)

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

好像有点zz了这个解法orz

select r.id,r.job,r.score,r.t_rank from
(select id, job, score, row_number() over(partition by job
                                         order by score desc) t_rank from grade) r
where (r.job,r.t_rank) in (select job, 
                           case when count(id) & 1 = 1 then (count(id)+1)*1.0/2
                           else count(id)*1.0/2+0.5
                           end d
                           from grade
                           group by job)
or (r.job,r.t_rank+0.5) in (select job, 
                           case when count(id) & 1 = 1 then (count(id)+1)*1.0/2
                           else count(id)*1.0/2+0.5
                           end d
                           from grade
                           group by job)
or (r.job,r.t_rank-0.5) in (select job, 
                           case when count(id) & 1 = 1 then (count(id)+1)*1.0/2
                           else count(id)*1.0/2+0.5
                           end d
                           from grade
                           group by job)
order by id
;
全部评论

相关推荐

11-01 08:48
门头沟学院 C++
伤心的候选人在吵架:佬你不要的,能不能拿户口本证明过户给我。。球球了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务