赞
踩
1、统计某一个月
- SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( 时间字段名, '%Y%m' ) ) =1 #当前月份统计
-
- SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) #某月统计
2、按月份聚合统计
- SELECT count(*) as '注册量',<DATE_FORMAT|FROM_UNIXTIME>(created_time,'%Y-%m') as '月份' FROM user GROUP BY <DATE_FORMAT|FROM_UNIXTIME>(created_time,'%Y-%m');
- SELECT count(*) as '报单量',<DATE_FORMAT|FROM_UNIXTIME>(created_time,'%Y-%m') as '月份' FROM loan GROUP BY <DATE_FORMAT|FROM_UNIXTIME>(created_time,'%Y-%m');
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。