title: Calculating the Median with Mysql
body: <p>I'm having trouble with calculating the median of a list of values, not the average.</p>
  
  <p>I found this article
  <a href="https://stackoverflow.com/questions/1291152/simple-way-to-calculate-median-with-mysql">Simple way to calculate median with MySQL</a></p>
  
  <p>It has a reference to the following query which I don't understand properly. </p>
  
  <pre><code>SELECT x.val from data x, data y
  GROUP BY x.val
  HAVING SUM(SIGN(1-SIGN(y.val-x.val))) = (COUNT(*)+1)/2
  </code></pre>
  
  <p>If I have a <code>time</code> column and I want to calculate the median value, what do the <code>x</code> and <code>y</code> columns refer to? </p>