title: mysql median value per month
body: <p>I am doing some queries from a database to make graphs, and a graph that may be needed is the median of a set of values per month. I know how to get the median of the whole set of our data, but for some reason I can't get GROUP BY MONTH(..) to separate the months so it returns the median per month.</p>
  
  <p>Here is the data that I have and I'd like for every month to get the median value for each month regardless of build type.</p>
  
  <pre><code>'Development', 1013.0164, 'June'
  'Development', 1170.8999, 'July'
  'Development', 671.2837, 'August'
  'Flash Assets', 2961.3832, 'June'
  'Flash Assets', 6662.2335, 'July'
  'Flash Assets', 3902.5000, 'August'
  'Release', 54.5499, 'June'
  'Release', 62.4832, 'July'
  'Release', 398.8500, 'August'
  'Repackage', 1360.0834, 'June'
  'Repackage', 6286.8505, 'July'
  'Repackage', 1274.7833, 'August'
  'Component', 16378.0161, 'June'
  'Component', 6063.5482, 'July'
  'Component', 23663.2496, 'August'
  'Source Diff', 1503.8834, 'June'
  'Source Diff', 1051.4500, 'July'
  'Source Diff', 73.7002, 'August'
  </code></pre>
  
  <p>I'd like to end up with this,</p>
  
  <pre><code>June, XXXX
  July, XXXX
  August, XXXX
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT: Current Query</strong></p>
  
  <p>This is the query that I am using right now to get the overall median, I am not sure how to translate this to getting it per month.</p>
  
  <pre><code> SELECT t.Data AS 'Median' FROM
   (SELECT CEIL(COUNT(*)/2.0) as 'Middle', s.Data as 'Data' FROM
   (SELECT bt.name as 'Labels', 
   SUM(TIME_TO_SEC(TIMEDIFF(bs.eventtime, b.submittime))/60.0) 
   AS 'Data', MONTHNAME(b.submittime) FROM builds b 
   JOIN buildstatuses bs ON bs.buildid = b.id 
   JOIN buildtypes bt ON bt.id = b.buildtype 
   WHERE MONTH(b.submittime) BETWEEN MONTH(CURDATE())-2 AND MONTH(CURDATE()) 
   AND bs.status LIKE 'Started HANDLER' 
   GROUP BY b.buildtype, MONTH(b.submittime) ORDER BY 'Data' ) s )t;
  </code></pre>