1、大牛的思路:当某一数的正序和逆序累计均大于整个序列的数字个数的一半即为中位数!
select grade from (select grade, (select sum(number) from class_grade) as total, #累和 sum(number) over(order by grade asc) as a, #正序 sum(number) over(order by grade desc) as b #倒序 from class_grade) where a >= total*1.0/2 and b >= total*1.0/2 #中位数条件 order by grade;
2、自己也想到了范围取值,有思路不熟悉啊用法啊,即利用between and实现,但大牛还是多。
select grade from (select *, (a.en - a.number) as st, sum(number) over() as total from (select *, sum(number) over(order by grade) as en from class_grade) a ) b where total/2 BETWEEN st and en;