mysql查询一天内,一周,一个月内的消费记录
查詢一天:
select?* from?表名 where?to_days(時(shí)間字段名) = to_days(now());
select?* from?表名?where?date(時(shí)間字段名) = curdate();
昨天
select?* from?表名 where?to_days( now( ) ) - to_days( 時(shí)間字段名) <= 1;
7天
select?* from?表名 where date_sub(curdate(), interval 7 day) <= date(時(shí)間字段名);
一周內(nèi)數(shù)據(jù)
select * from?表名 where 時(shí)間字段名 between current_date()-7 and sysdate();
近30天
select?* from?表名 where date_sub(curdate(), interval?30 day) <= date(時(shí)間字段名);
select?* from?tbl_name?where?to_days(now()) - to_days(date_col) <= 30;?
本月
select?* from?表名 where?date_format( 時(shí)間字段名, '%Y%m' ) = date_format(curdate( ) , '%Y%m' )
?
查詢一個(gè)月
select * from table where date_sub(curdate(), interval?1 month) <= date(column_time);
上一月
select?* from?表名 where?period_diff( date_format( now( ) , '%Y%m' ) , date_format( 時(shí)間字段名, '%Y%m' ) ) =1
總結(jié)
以上是生活随笔為你收集整理的mysql查询一天内,一周,一个月内的消费记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 0033__PDM,全称为 Persep
- 下一篇: 如何优雅地管理微信数据库?