自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL查詢本周、上周、本月、上個月份的數(shù)據(jù)

數(shù)據(jù)庫 MySQL
查詢是MySQL數(shù)據(jù)庫使用中最常用的操作,下文介紹的幾種查詢方式都是針對不同時間段內(nèi)的查詢,希望對您能夠有些幫助。

MySQL查詢的方式很多,下面為您介紹的MySQL查詢實(shí)現(xiàn)的是查詢本周、上周、本月、上個月份的數(shù)據(jù),如果您對MySQL查詢方面感興趣的話,不妨一看。

查詢當(dāng)前這周的數(shù)據(jù)
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());

查詢上周的數(shù)據(jù)
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;

查詢當(dāng)前月份的數(shù)據(jù)
select name,submittime from enterprise   where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')

查詢距離當(dāng)前現(xiàn)在6個月的數(shù)據(jù)
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();

查詢上個月的數(shù)據(jù)
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 下月***天

 

 

【編輯推薦】

MySQL查詢超時問題的解決

改造自discuz的MySQL查詢類

使用Limit參數(shù)實(shí)現(xiàn)MySQL查詢優(yōu)化

MySQL查詢表字段個數(shù)的兩種方法

MySQL查詢中日期格式轉(zhuǎn)換函數(shù)簡介

責(zé)任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2018-09-06 12:47:56

編程語言PythonC++

2017-09-06 10:34:14

數(shù)據(jù)庫排名DB-Engines

2021-05-17 10:59:54

手機(jī)智能數(shù)據(jù)

2011-07-19 16:14:39

SQLite數(shù)據(jù)庫

2021-10-03 14:51:15

數(shù)據(jù)庫排名MySQL

2020-08-13 11:55:33

編程語言JavaPython

2017-06-02 15:00:32

MySQLOracle數(shù)據(jù)庫排名

2024-05-06 07:22:50

Windows 11

2020-08-04 08:21:14

Windows 10Windows微軟

2015-06-12 10:33:36

2021-04-02 12:51:03

數(shù)據(jù)庫DB-EnginesMongoDB

2009-03-30 13:23:32

NehalemIntel服務(wù)器

2021-03-12 15:50:54

Windows 10Windows操作系統(tǒng)

2021-09-29 00:20:42

惡意軟件漏洞

2021-09-17 10:10:57

漏洞安全補(bǔ)丁零日漏洞

2021-07-09 14:18:15

數(shù)據(jù)庫DB-EnginesOracle

2015-02-04 10:47:15

操作系統(tǒng)

2021-03-05 11:40:26

數(shù)據(jù)庫SQL Server排名

2021-02-19 07:15:40

Windows10操作系統(tǒng)微軟

2009-03-28 09:17:21

GoogleRim黑莓
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號