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

最差是第几名(二)

http://www.nowcoder.com/practice/165d88474d434597bcd2af8bf72b24f1

借鉴其他大佬的思路,先构造区间,最后加上判断奇偶

select grade from
    (select grade, number, sum(number) over(order by grade) s from class_grade
    order by grade)
where (s-number < (select sum(number) from class_grade)*1.0/2 and s >= (select sum(number) from class_grade)*1.0/2)
or (s-number < (select sum(number) from class_grade)*1.0/2+1 and s >= (select sum(number) from class_grade)*1.0/2+1)
limit (select case when sum(number) & 1 = 1 then 1 else 2 end from class_grade)
;
全部评论

相关推荐

蚂蚁 基架java (n+6)*16 签字费若干
点赞 评论 收藏
分享
10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务