Skip to content

Instantly share code, notes, and snippets.

@alibitek
Created June 5, 2016 05:59
Show Gist options
  • Save alibitek/ee0e32c00a9a78833572d71d2aaaca1f to your computer and use it in GitHub Desktop.
Save alibitek/ee0e32c00a9a78833572d71d2aaaca1f to your computer and use it in GitHub Desktop.
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