MySQL查询本日、昨天、本周、本月、48小时内、30分钟内记录

1、查询本日:

select sum(reward) from  manarewards
where uid = #{uid}
and to_days(createtime) = to_days(now());

2、查询本周:

select sum(reward) from  manarewards
where uid = #{uid}
and YEARWEEK(date_format(createtime ,'%Y-%m-%d')- INTERVAL 1 DAY) = YEARWEEK(now()  - INTERVAL 1 DAY)

ps:国外周日算第一天,相当于早了一天,到周日时计算到下一周了,减去1天计算本周。

3、查询本月:

SELECT * FROM wx_fund_record  WHERE store_id=1 AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )

 4、查询48小时内数据:

select count(1) from cashouts
where   DATE(cashtime) > date_sub(curdate(),interval 2 day) 

5、30分钟内记录

 select * from orders
 where state = 0 and orderTime>CURRENT_TIMESTAMP - INTERVAL 30 MINUTE

 6、昨天记录

 select *from plans where date(plantime)= DATE(NOW() - INTERVAL 1 DAY)

 

posted @ 2021-03-23 09:32  好学Ace  阅读(1538)  评论(0编辑  收藏  举报