MySQL查詢本周、上周、本月、上個(gè)月份數(shù)據(jù)的sql代碼
更新時(shí)間:2012年11月29日 19:57:49 作者:
MySQL查詢的方式很多,下面為您介紹的MySQL查詢實(shí)現(xiàn)的是查詢本周、上周、本月、上個(gè)月份的數(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個(gè)月的數(shù)據(jù)
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
查詢上個(gè)月的數(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 下月第一天
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個(gè)月的數(shù)據(jù)
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
查詢上個(gè)月的數(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 下月第一天
相關(guān)文章
一次Mysql?update?sql不當(dāng)引起的生產(chǎn)故障記錄
這篇文章主要給大家介紹了關(guān)于一次Mysql?update?sql不當(dāng)引起的生產(chǎn)故障的相關(guān)資料,由于update涉及到數(shù)據(jù)的修改,所以很容易推斷,update語句比select語句會更復(fù)雜一些,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04淺談mysql explain中key_len的計(jì)算方法
下面小編就為大家?guī)硪黄獪\談mysql explain中key_len的計(jì)算方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04MySQL實(shí)現(xiàn)主從復(fù)制的原理詳解
這篇文章主要為大家介紹了MySQL的主從復(fù)制是怎么實(shí)現(xiàn)的,文中有相關(guān)的圖文介紹和代碼示例,具有一定的參考價(jià)值,感興趣的同學(xué)跟著小編一起來學(xué)習(xí)吧2023-07-07MySql 錯誤Incorrect string value for column
能使用中文進(jìn)行搜索,但是insert into 中文是可以的。我的數(shù)據(jù)庫和數(shù)據(jù)表中所有的charset都是設(shè)置的utf8。2010-12-12