Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'imx365.album_images.screen_datetime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SELECT DATE_FORMAT(screen_datetime, '%m') AS month, DATE_FORMAT(screen_datetime, '%Y-%m-01') AS year_month_01, COUNT(*) AS image_count FROM album_images WHERE userid = 175008 AND DATE_FORMAT(screen_datetime, '%Y') BETWEEN '' AND '1' GROUP BY DATE_FORMAT(screen_datetime, '%m') HAVING COUNT(*) >= 1