mysql按日、周、月、季度统计数据

1.使用DATE_FORMAT做等值条件查询

2.DATE_FORMAT函数语法,参考w3school

 

3.可使用格式

  

 4.使用示例

-- 日
select * from task_user where DATE_FORMAT(start_time,'%Y%m%d') = DATE_FORMAT( CURDATE( ) , '%Y%m%d')
-- 周
select * from task_user where DATE_FORMAT(start_time,'%Y%m%u') = DATE_FORMAT( CURDATE( ) , '%Y%m%u')
-- 月
select * from task_user where DATE_FORMAT(start_time,'%Y%m') = DATE_FORMAT( CURDATE( ) , '%Y%m')
-- 季度
select * from task_user where  quarter(start_time) = quarter(curdate())
-- 年 
select * from task_user where DATE_FORMAT(start_time,'%Y') = DATE_FORMAT( CURDATE( ) , '%Y')

猜你喜欢

转载自blog.csdn.net/weixin_40333020/article/details/88574983