1SET @rowindex := -1;
2
3SELECT
4 AVG(g.grade)
5FROM
6 (SELECT @rowindex:=@rowindex + 1 AS rowindex,
7 grades.grade AS grade
8 FROM grades
9 ORDER BY grades.grade) AS g
10WHERE
11g.rowindex IN (FLOOR(@rowindex / 2) , CEIL(@rowindex / 2));
12