title: Any ideas to optimize MySQL query with JOIN GROUP and ORDER BY
body: <p>I have a query below.</p>
  
  <pre><code>SELECT `user`.id, title, something, SUM(cnt) AS `total`, 
  FROM `user` 
  LEFT JOIN `stat_per_day` ON stat_per_day.user_id = user.id  
  WHERE CAST(stat_per_day.created_at AS DATE) BETWEEN '2017-08-12' and '2017-09-12'
  GROUP BY `user`.`id` 
  ORDER BY `total` DESC 
  LIMIT 250;
  </code></pre>
  
  <p>Both tables has approx. 500k records.</p>
  
  <p>Table <code>stat_per_day</code> structure:</p>
  
  <p><code>id | created_at | user_id | cnt</code></p>
  
  <p>I'm trying to use indexes, but does not get speed up.
  The problem is that I need to receive ordered data for an any period.
  Also, if i remove <code>ORDER BY</code> it runs faster, but i need this order.</p>
  
  <p>Any ideas?
  Thank you in advance.</p>