1 SELECT DATE_FORMAT(releaseDate,"%Y年%m月") AS dates,COUNT(*) FROM t_diary GROUP BY DATE_FORMAT(releaseDate,"%Y年%m月")
ORDER BY DATE_FORMAT(releaseDate,"%Y年%m月") DESC ;
releaseDate 日期 t_diary表名
DATE_FORMAT();按照格式对某个日期操作
ORDER BY 排序
DESC 降序
整段代码的意思是:从t_diary表中 查询日期(releaseDate)(将日期按照"%Y年%m月"格式)并作为dates,统计数量(count(*)),按照日期分组 GROUP BYDATE_FORMAT(releaseDate,"%Y年%m月"),并降序 ORDER BY DATE_FORMAT(releaseDate,"%Y年%m月") DESC 。
个人微信公众号