Created
July 27, 2012 08:00
-
-
Save daveslutzkin/3186735 to your computer and use it in GitHub Desktop.
SQL code to calculate the median
This file contains 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 from_unixtime(timecreated,"%Y-%m") as month,(substring_index(substring_index(group_concat(t._price order by t._price), ',', ceiling(count(*)/2)), ',', -1) + substring_index(substring_index(group_concat(t._price order by t._price), ',', -ceiling(count(*)/2)), ',', 1)) / 2 as median from auction t where status='won' group by month; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment