title: mysql get latest date record in ascending order
body: <p>I have following "stats" table: </p>
  
  <p><img src="https://i.stack.imgur.com/qsmVw.jpg" alt="enter image description here"></p>
  
  <p>I want mysql query that return latest 5 date with sum of clicks. So starting record should be 2015-01-12</p>
  
  <p>Output: </p>
  
  <p><img src="https://i.stack.imgur.com/ZQVbm.jpg" alt="enter image description here"></p>
  
  <p>So far i have written following query that doesn't work according to my output.</p>
  
  <pre><code>SELECT logdate, (
      SELECT SUM(clicks)
      FROM stats t2
      WHERE t2.logdate = t1.logdate
      ORDER BY t2.logdate
      DESC LIMIT 0,5
  ) as clicks
  FROM stats t1
  GROUP BY t1.logdate
  ORDER BY t1.logdate ASC
  LIMIT 0, 5
  </code></pre>