解释:
DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。
1、表字段格式:
按天分组很好做直接 GROUP BY date
##按日期分组
SELECT sum(public) public FROM tax GROUP BY date;
##按月分组 as 别名不能跟原始字段名重复
SELECT DATE_FORMAT(date,'%Y-%m') as time,sum(public) public FROM tax GROUP BY time;
##按年分组
SELECT DATE_FORMAT(date,'%Y') as time,sum(public) public FROM tax GROUP BY time;