SQL 88) 最差是第几名(二)
最差是第几名(二)
http://www.nowcoder.com/questionTerminal/165d88474d434597bcd2af8bf72b24f1
参考大牛的解法,绝了
当某一数的正序和逆序累计均大于整个序列的数字个数的一半即为中位数
select grade from (select grade, (select sum(number) from class_grade) as total, sum(number)over(order by grade) a, -- 求正序 sum(number)over(order by grade desc) b -- 求逆序 from class_grade order by grade)t where a >= total/2 and b >= total/2 -- 正序逆序均大于整个数列数字个数的一半 order by grade;
SQL 文章被收录于专栏
SQL