1,当前月
SELECT DATE_FORMAT(check_time,'%Y-%m-%d') as time, COUNT(*) FROM dw_rule WHERE check_state = 3 AND
DATE_FORMAT( check_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) GROUP BY time
2,最近30天,不包括当天
因为mybatis里面用<=会报错,所以加上CDATA区
SELECT DATE_FORMAT(check_time,'%Y-%m-%d') as time, COUNT(*) FROM dw_rule WHERE check_state = 3
<![CDATA[ AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= check_time ]]> GROUP BY time
表中时间为日期格式
DATE_FORMAT(create_time,'%Y-%m-%d') as time
表中时间为时间戳格式
FROM_UNIXTIME(create_time,'%Y-%m-%d') as time