title: How to find the SQL medians for a grouping
body: <p>I am working with SQL Server 2008</p>
  
  <p>If I have a Table as such:</p>
  
  <pre><code>Code   Value
  -----------------------
  4      240
  4      299
  4      210
  2      NULL
  2      3
  6      30
  6      80
  6      10
  4      240
  2      30
  </code></pre>
  
  <p>How can I find the median AND group by the Code column please?
  To get a resultset like this:</p>
  
  <pre><code>Code   Median
  -----------------------
  4      240
  2      16.5
  6      30
  </code></pre>
  
  <p>I really like this solution for median, but unfortunately it doesn't include Group By:
  <a href="https://stackoverflow.com/a/2026609/106227">https://stackoverflow.com/a/2026609/106227</a></p>