解题思路

  1. 将grade的名次的范围找出来
select grade,(select sum(number) from class_grade c1 where c1.grade < c2.grade) as s, (select sum(number) from class_grade c1 where c1.grade <= c2.grade) as e
from class_grade c2
order by grade
grade start end
A None 2
B 2 6
C 6 10
D 10 12
  1. 判断 sum(number/2) 的值在 grade 的那个区间内即可.
select grade from 
    (select grade,(select sum(number) from class_grade c1 where c1.grade < c2.grade) as s, (select sum(number) from class_grade c1 where c1.grade <= c2.grade) as e
    from class_grade c2
    order by grade) as t1 , (select sum(number) as sums from class_grade) as t2
    where (sums/2) between s and e