mysql查询指定时间范围的数据

查询当天数据

select count(1) from crm_cust_info where user_id = '85e20499438e6f0c7296a68530aea53a' and to_days(create_date) = to_days(now()) and cust_source = 2

查询指定天数前的数据

select count(1) from crm_cust_info where user_id = '85e20499438e6f0c7296a68530aea53a' and  to_days(now())-to_days(create_date) = 1 and cust_source = 2

查询一周内的数据

select count(1) from crm_cust_info where user_id = '85e20499438e6f0c7296a68530aea53a' and YEARWEEK(date_format(create_date,'%Y-%m-%d')) = YEARWEEK(now()) and cust_source = 2

查询一个月内的数据

select count(1) from crm_cust_info where user_id = '85e20499438e6f0c7296a68530aea53a' and date_format(create_date,'%Y-%m') = DATE_FORMAT(CURDATE(),'%Y-%m' ) and cust_source = 2

版权声明:本文为qq_56042039原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END
< <上一篇
下一篇>>