mysql+ mybatis查询最近十二个月的数据

版权声明:巴啦啦小魔仙乌卡拉卡,变身---------------------------------------xiner https://blog.csdn.net/zhengsaisai/article/details/86554761
select count(*) as 'number',left(createtime,7) as 'month' from t_hotel
		where DATE_FORMAT(createtime,'%Y-%m')>
		DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')
		group by month;

说明:

我这里查询的是总量,可以根据需要将count(*)改为合适字段。

t_hotel 表名

createtime 日期字段

number 别名

例如当前日期为2019-01-19

使用上述sql语句查询结果为:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/zhengsaisai/article/details/86554761