title: How to write a query to find Median of column in a Table in MySql?
body: <p>I was trying to solve problem in Hackerrank SQL Practice section and stuck in Problem 'Weather Observation Problem 20'.</p>
  <p>To find Median, I though of the following approach:</p>
  <ol>
  <li>sub-query to count the lower half of the entries.</li>
  <li>sub-query to count the upper half of the entries.</li>
  <li>Equate these queries together under a WHERE clause (so that an entry has the same number of entries before and after).</li>
  </ol>
  <p>QUERY:</p>
  <pre><code>select round(s.lat_n,4) 
  from station s 
  where (
          select round(count(s.id)/2)-1 
          from station
      ) = (
          select count(s1.id) 
          from station s1 
          where s1.lat_n &gt; s.lat_n
      );
  </code></pre>
  <p>PLEASE HELP ME OUT WITH THE OPTIMIZED QUERY.</p>
  <p>LINK OF PROBLEM STATEMENT : <a href="https://www.hackerrank.com/challenges/weather-observation-station-20/problem" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/weather-observation-station-20/problem</a></p>