2012-12-19 10:47:39
| 分類:
mysql|字型大小
訂閱 查詢當天資料
select * from tab where from_unixtime(fabutime, '%y%m%d') = 20121217;
mysql to_days(date) 函式
to_days(date)
給定乙個日期date, 返回乙個天數 (從年份0開始的天數 )。
mysql> select to_days(950501);
-> 728779
mysql查詢今天、昨天、7天、近30天、本月、上一月 資料
今天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));
sql查詢當天 資料
今天的所有資料 select from 表名 where datediff dd,datetime型別字段,getdate 0 昨天的所有資料 select from 表名 where datediff dd,datetime型別字段,getdate 1 7天內的所有資料 select from 表...
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...
mysql 查詢當天當周當月的資料
1 查詢當天的資料 select from 表名 where to days 時間字段 to days now 2 查詢當周的資料 select from 表名 where yearweek date format 時間字段,y m d yearweek now 3 查詢當月的資料 select f...