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
) t
where a >= total/2 and b >= total/2
order by grade