mysql查詢前段時間 Mysql 查詢某一段時間

2021-10-17 13:09:25 字數 1040 閱讀 1618

朋友問我時間查詢的的sql,閒下來統計了一下,應該回滿足需求的,特殊的查詢暫時沒想到。

今天select*from表名whereto_days(時間欄位名)=to_days(now());

昨天select*from表名whereto_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 表名 where quarter(create_date)=quarter(now());

查詢上季度資料

select * from 表名  where quarter(create_date)=quarter(date_sub(now(),interval1quarter));

查詢本年度

select * from  表名 where year(create_date)=year(now());

查詢上年度

select * from 表名 where year(create_date)=year(date_sub(now(),interval 1 year));

查詢當前周的資料

select * from 表名 where year week(date_format(表列名,'%y-%m-%d'))= year week(now());

前段時間總結

咱先來重頭戲,開門見山的說 桶式排序的思想,推廣之後得到雜湊查詢,以及對應雜湊函式的功能。將乙個整數 字串或者其他的資料通過雜湊函式對映 單射,但不一定是滿射 到一根自然數的數軸上。訪問都通過公式 來得到所在的位址,並完成操作。如此,則無論資料規模多大,只要還在雜湊函式的定義域之內 當然還得有雜湊函...

前段時間讀了些關於SOCKET的資料

前段時間讀了些關於socket的資料 感覺以前用vb寫的 木馬都是小兒科 不過筆者用vb開發木馬時還在讀高二,呵呵還是可以理解的 於是決定用socket親自實踐下真正的木馬 先做伺服器部分 按照流式套接字規範 建立本地套接字 繫結埠 非同步選擇機制wsaasyncselect 產生你感興趣的事件訊息...

找到實習了,感謝ITeyer前段時間的幫助

聽前輩的話在看 的同時又投了幾個簡歷,上星期一輪面試,北京ibm cstl收到offer,上海emc收到2面通知,實在不敢賭一定成功,所以答應了北京的職位。一方面向先前幫助過我的前輩表示感謝,另一方面也藉此立證一心一意認真學習 工作。實習的機會感覺還是很難得的,一方面導師肯答應 雖然有很多要求,比如...