MySQL 统计过去12个月的数据

select 
  		DATE_FORMAT(CREATED_DT,'%Y-%m') months, count(SID) count 
  	from *** 
  	where 
  		1 = 1 and DATE_FORMAT(CREATED_DT,'%Y-%m') > DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') 
  		group by months

截图:

发布了1266 篇原创文章 · 获赞 275 · 访问量 290万+

猜你喜欢

转载自blog.csdn.net/zhouzhiwengang/article/details/103787597