mysql取周,月,年資料

2021-07-31 20:22:41 字數 1258 閱讀 8061

查詢當前這週的資料 

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(now(),'%y-%m') 

查詢距離當前現在6個月的資料 

select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now(); 

查詢上個月的資料 

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 下月第一天

取兩個日期相差幾年 資料取對數的意義

平時在一些資料處理中,經常會把原始資料取對數後進一步處理。之所以這樣做是基於對數函式在其定義域內是單調增函式,取對數後不會改變資料的相對關係,取對數作用主要有 1.縮小資料的絕對數值,方便計算。例如,每個資料項的值都很大,許多這樣的值進行計算可能對超過常用資料型別的取值範圍,這時取對數,就把數值縮小...

MySQL 間隔取資料

背景介紹 系統中存在一張座標表,訪問一段路線樁號的具體座標,座標點多且密,如果全部返回給前端,後端介面響應很慢,為了解決這個問題,準備在查詢資料庫的時候,間隔取出一些座標點即可,如每十個樁號取乙個即可 資料表如下 具體實現 select n,id,longitude,latitude from se...

MYSQL統計每天 每週 每月 每年資料

select count 1 as total,date format created time,y m d as days from task execution group by days desc select count 1 as total,week created time as wee...