mysql 查詢乙個月的資料

2021-09-30 01:17:11 字數 2330 閱讀 1234

查詢語句

//今天

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 7 day) <= date(時間欄位名)

//近30天

select * from 表名 where date_sub(curdate(), interval 30 day) <= date(時間欄位名)

//本月

select * from 表名 where date_format( 時間欄位名, '%y%m' ) = date_format( curdate( ) , '%y%m' )

//上一月

select * from 表名 where period_diff( date_format( now( ) , '%y%m' ) , date_format( 時間欄位名, '%y%m' ) ) =1

//查詢本季度資料

select * from `ht_invoice_information` where quarter(create_date)=quarter(now());

//查詢上季度資料

select * from `ht_invoice_information` where quarter(create_date)=quarter(date_sub(now(),interval 1 quarter));

//查詢本年資料

select * from `ht_invoice_information` where year(create_date)=year(now());

//查詢上年資料

select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));

//查詢當前這週的資料

select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now());

//查詢上週的資料

select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())-1;

//查詢上個月的資料

select name,submittime from enterprise where date_format(submittime,'%y-%m')=date_format(date_sub(curdate(), interval 1 month),'%y-%m')

select * from user where date_format(pudate,'%y%m') = date_format(curdate(),'%y%m') ;

select * from user where weekofyear(from_unixtime(pudate,'%y-%m-%d')) = weekofyear(now())

select * from user where month(from_unixtime(pudate,'%y-%m-%d')) = month(now())

select * from user where year(from_unixtime(pudate,'%y-%m-%d')) = year(now()) and month(from_unixtime(pudate,'%y-%m-%d')) = month(now())

select * from user where pudate between 上月最後一天 and 下月第一天

//查詢當前月份的資料

select name,submittime from enterprise where date_format(submittime,'%y-%m')=date_format(now(),'%y-%m')

select 

user_id,

user_name,

createtime

from

t_user

where

date_sub(curdate(), interval 1 month) <= date(createtime);

參考**:

頹廢的乙個月

哎,九月末到十月末實在是太頹廢了。其實是因為不想面對一些事。但現在想想,是我自己忘記了最初的夢想,之去追求一些有的沒的的,所以才如此不精進。記得那幾天玩的也不好,每每想到自己還沒學好,還是個醬油的時候,就很煩惱。室友也說我,為什麼最近不怎麼去實驗室了?我也不知道怎麼回答。甚至可以躺床上一整天,一直躺...

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 interv...

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 interv...