select
t2.grade
from
(
select
t1.grade,
case when mod(t1.total,2)=0 then total/2 else (total+1)/2 end star,
case when mod(t1.total,2)=0 then total/2+1 else (total+1)/2 end ending,
ifnull(lag(t1.ct)over(),0) ct0,
t1.ct
from (
select
grade,
(select sum(t.number) from class_grade t) total,
sum(number)over(order by grade) ct
from class_grade
order by 1) t1
) t2
where (t2.ct0 < star and star <= t2.ct) or (t2.ct0 < ending and ending <= t2.ct)