how to find median of a column sql

Solutions on MaxInterview for how to find median of a column sql by the best coders in the world

showing results for - "how to find median of a column sql"
Leda
18 Apr 2019
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