代碼如下
在瀏陽等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網(wǎng)站設計制作、成都做網(wǎng)站 網(wǎng)站設計制作按需定制開發(fā),公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,高端網(wǎng)站設計,成都營銷網(wǎng)站建設,外貿(mào)網(wǎng)站建設,瀏陽網(wǎng)站建設費用合理。
select?group_date?groupDate?from?(
SELECT
@cdate?input_date,
@last_sat?:=?date_add(date_sub(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),?interval?6-date_format(date_sub(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),'%w')?day)?last_sat,
@this_sat?:=?date_add(date_sub(@cdate,interval??day(@cdate)-1?day),?interval?6-date_format(date_sub(@cdate,interval??day(@cdate)-1?day),'%w')?day)?this_sat,
@next_sat?:=?date_add(date_add(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),?interval?6-date_format(date_add(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),'%w')?day)?next_sat,
@last_point?:=?if(day(@last_sat)-30,date_sub(@last_sat,interval?7?day),@last_sat)?last_point,
@this_point?:=?if(day(@this_sat)-30,date_sub(@this_sat,interval?7?day),@this_sat)?this_point,
@next_point?:=?if(day(@next_sat)-30,date_sub(@next_sat,interval?7?day),@next_sat)?next_point?,
case
when?@cdate?=?@last_point?and?@cdate??@this_point?then
concat(
'W',
datediff(@cdate,@last_point)?div?7?+?1,?'/',
year(@cdate),'-',
if(month(@last_sat)=10,month(@last_sat),concat('0',month(@last_sat)))
)
when?@cdate?=@this_point?and?@cdate??@next_point?then
concat(
'W',
datediff(@cdate,@this_point)?div?7?+?1,'/',
year(@cdate),'-',
if(month(@this_sat)=10,month(@this_sat),concat('0',month(@this_sat))))
else
concat(
'W',
datediff(@cdate,@next_point)?div?7?+?1,'/',
year(@cdate),'-',if(month(@next_sat)=10,month(@next_sat),concat('0',month(@next_sat))))
end
group_date
from??(SELECT?@cdate?:=?#{inputDate})?as?gd
);
7天內(nèi)的:
select * from news where inputtime between DATE_ADD(NOW(), INTERVAL -7 DAY) and now()
本周的:
select * from news where DATE_FORMAT(inputtime,"%U")= DATE_FORMAT(now(),"%U")
DATE_FORMAT(now(),"%U")表示今天是1年的第幾個周,0~53
mysql中怎么查詢一周內(nèi),三個月內(nèi)\x0d\x0a使用sql語句查詢?nèi)掌谠谝恢軆?nèi)的數(shù)據(jù)\x0d\x0aselect * from ShopOrder where datediff(week,ordTime,getdate()-1)=0 //查詢當天日期在一周年的數(shù)據(jù)\x0d\x0aselect * from ShopOrder where datediff(day,ordTime,getdate()-1)=0 //查詢當天的所有數(shù)據(jù)\x0d\x0a SELECT * FROM A where datediff(d,datetime,getdate())
回答于?2022-12-11
mysql
DATE_FORMAT(date,'%Y-%U') 按周查詢
%U 周 (00-53) 星期日是一周的第一天