求中位值SQL
中位值:是将所给的一组数从小到大或从大到小排列,奇数个数的话取中间的数字,偶数个数的话取中间两个数的平均数。
SET @rowindex := -1;
SELECT
round(AVG(g.LAT_N),4)
FROM
(SELECT @rowindex:=@rowindex + 1 AS rowindex,
station.LAT_N AS LAT_N
FROM station
ORDER BY station.LAT_N) AS g
WHERE
g.rowindex IN (FLOOR(@rowindex / 2) , CEIL(@rowindex / 2));