MySQL解法:

SELECT a.grade
FROM (
SELECT c.grade,c.number,
SUM(c.number) OVER(ORDER BY c.grade) AS t_rank_max
FROM class_grade AS c
) AS a
WHERE (
a.t_rank_max>=(
SELECT floor(SUM(b.number)1.0/2)+1
FROM class_grade AS b
) AND a.t_rank_max-a.number+1<=(
SELECT floor(SUM(b.number)
1.0/2)+1
FROM class_grade AS b
)
) OR(
a.t_rank_max>=(
SELECT ceil(SUM(b.number)1.0/2)
FROM class_grade AS b
) AND a.t_rank_max-a.number+1<=(
SELECT ceil(SUM(b.number)
1.0/2)
FROM class_grade AS b
)
)
ORDER BY a.grade