题解 | #最差是第几名(二)#
最差是第几名(二)
http://www.nowcoder.com/practice/165d88474d434597bcd2af8bf72b24f1
学习评论第一天的思想,顺序和逆序的排名都大于总数的一半为中位数```sql select grade from ( SELECT grade, (SELECT SUM(NUMBER) FROM class_grade) total, sum(number) over(order by grade ) head, sum(number) over(order by grade desc) back FROM class_grade GROUP BY grade )tmp WHERE head >= total/2 and back >= total/2 order by grade;