Can I speed up this slow query which should be limited by MIN/MAX values?
This should work:

CREATE TEMPORARY TABLE user_retention_temp (first DATE, last DATE, amount INT);

INSERT INTO user_retention_temp
(SELECT MIN(ymd) AS first, MAX(ymd) AS last, player_id 
   FROM day_item 
  GROUP BY player_id
  HAVING first &gt;= ? AND last &lt; ?);