mysql group by 以后默认返回每组中的第一条数据,所以无法达到“查询每个月最后一个日期” 这个要求
SELECT id, DATE_FORMAT(DD,'%Y-%m') AS datestr FROM AAA GROUP BY datestr
要适应在group by 语句中配合max() 等聚合函数啊!!!
SELECT id, max(dd), DATE_FORMAT(dd,'%Y-%m') AS datestr FROM AAA GROUP BY datestr
mysql group by 以后默认返回每组中的第一条数据,所以无法达到“查询每个月最后一个日期” 这个要求
SELECT id, DATE_FORMAT(DD,'%Y-%m') AS datestr FROM AAA GROUP BY datestr
要适应在group by 语句中配合max() 等聚合函数啊!!!
SELECT id, max(dd), DATE_FORMAT(dd,'%Y-%m') AS datestr FROM AAA GROUP BY datestr