Skip to content

Instantly share code, notes, and snippets.

@daveslutzkin
Created July 27, 2012 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveslutzkin/3186735 to your computer and use it in GitHub Desktop.
Save daveslutzkin/3186735 to your computer and use it in GitHub Desktop.
SQL code to calculate the median
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