Created
June 5, 2016 05:59
-
-
Save alibitek/ee0e32c00a9a78833572d71d2aaaca1f to your computer and use it in GitHub Desktop.
MySQL median value - http://stackoverflow.com/a/7263925/313113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT round(avg(t1.LAT_N), 4) as median_val | |
FROM ( | |
SELECT @rownum := @rownum+1 as `row_number`, | |
s.LAT_N | |
FROM STATION s, | |
(SELECT @rownum := 0) r | |
ORDER BY s.LAT_N | |
) as t1, | |
( | |
SELECT count(*) as total_rows | |
FROM STATION s | |
) as t2 | |
WHERE t1.row_number in ( floor((total_rows+1)/2), floor((total_rows+2)/2) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment