题解 | 窗口函数求解
最差是第几名(二)
http://www.nowcoder.com/practice/165d88474d434597bcd2af8bf72b24f1
SELECT grade FROM ( SELECT grade, SUM(number) OVER(ORDER BY grade) AS rk1,#累计求和正序排序 SUM(number) OVER(ORDER BY grade DESC) AS rk2,#累计求和倒序排序 SUM(number) OVER() AS total #求人数的最大值 FROM class_grade ORDER BY grade ) AS t WHERE rk1 >= total/2 AND rk2 >= total/2 ORDER BY grade