mysql 查詢當天當周當月的資料

2022-07-08 22:18:11 字數 761 閱讀 3183

1、查詢當天的資料

select * from 表名 where to_days(時間字段)=to_days(now());

2、查詢當周的資料

select * from 表名 where yearweek(date_format(時間字段,'%y-%m-%d'))=yearweek(now());

3、查詢當月的資料

select * from 表名 where date_format(時間字段,'%y%m')=date_format(curdate(),'%y%m');

4、查詢昨天的資料

select * from 表名 where to_days(now())-to_days(時間字段)=1;

5、查詢最近7天的資料

select * from 表名 where date_sub(curdate(),interval 7 day)<=date(時間字段);

6、查詢當年的資料

select * from 表名 where year(時間字段) =year(now());

7、查詢上週的資料

select * from 表名 whereyearweek(date_format(時間字段,'%y-%m-%d'))=yearweek(now())-1;

8、查詢上月的資料

select *from 表名

where period_diff(date_format(now(),'%y%m'),date_format(時間字段,'%y%m';

**:

使用sql 語句查詢當月 當天 當周的資料總和

select from article where to days add time to days now 查詢昨天的資訊記錄 select to days now from system.dual select getdate from system.dual 根據日期增量判定,求取日期區間 s...

MySQL查詢當天當月資料

今天 select from 表名 where to days 時間欄位名 to days now 昨天 select from 表名 where to days now to days 時間欄位名 1 近 7天 select from 表名 where date sub curdate inter...

sql查詢當天 當月 當年

今天 select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days 時間欄位名 1 近7天select from 表名 where date sub curdate interval...