题解 | #查找在职员工自入职以来的薪水涨幅情况#
最差是第几名(二)
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)
;