title: MySQL - Calculate Median in Select Statement
body: <p>I have a table in MySQL with following structure.</p>
  <pre><code>CREATE TABLE MyTable (id CHAR(10), name CHAR(10), price INT, cat INT, size INT);
  
  INSERT INTO MyTable (id, name, price, cat, size) 
  VALUES ('2065511307', 'abc', 2449, 1, 600), 
         ('65fH72', 'bcd', 4395, 1, 851), 
         ('65fH72', 'bcd', 4995, 2, 985),
         ('65fH72', 'bcd', 4678, 1, 865);
  </code></pre>
  <p>I am calculating aggregate values using functions like <code>AVG</code>, however, I'd like to calculate the <code>Median</code> instead.</p>
  <p>How do I modify the following query to get <code>median</code> instead of <code>mean</code>?</p>
  <pre><code>SELECT id, cat, AVG(price) AS avg_price, AVG(size) AS avg_size
  FROM MyTable
  GROUP BY id, cat
  HAVING avg_price &lt;= 10000
  </code></pre>
  <p>The <code>median</code> will be calculated for <code>price</code> and <code>size</code> columns for each group.</p>