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

最差是第几名(二)

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)
;
全部评论

相关推荐

一个非常好用的遍历方法
AomaYple:不是指针,是引用
点赞 评论 收藏
分享
点赞 评论 收藏
分享
小红书 后端开发 总包n+8w+期权
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务