mysql怎么查询当前周 mysql查询本周数据

mysql中怎么查询一周内 , 三个月内,半年内的数据?mysql中怎么查询一周内,三个月内\x0d\x0a使用sql语句查询日期在一周内的数据\x0d\x0aselect * from ShopOrder where datediff(week,ordTime,getdate()-1)=0//查询当天日期在一周年的数据\x0d\x0aselect * from ShopOrder where datediff(day,ordTime,getdate()-1)=0//查询当天的所有数据\x0d\x0a SELECT * FROM A where datediff(d,datetime,getdate())
回答于 2022-12-11
在mysql中得到当前日期是当月第几周代码如下
select group_date groupDate from (
SELECT
@cdate input_date,
@last_sat := date_add(date_sub(date_sub(@cdate,intervalday(@cdate)-1 day),interval 1 month), interval 6-date_format(date_sub(date_sub(@cdate,intervalday(@cdate)-1 day),interval 1 month),'%w') day) last_sat,
@this_sat := date_add(date_sub(@cdate,intervalday(@cdate)-1 day), interval 6-date_format(date_sub(@cdate,intervalday(@cdate)-1 day),'%w') day) this_sat,
@next_sat := date_add(date_add(date_sub(@cdate,intervalday(@cdate)-1 day),interval 1 month), interval 6-date_format(date_add(date_sub(@cdate,intervalday(@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))))
【mysql怎么查询当前周 mysql查询本周数据】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
);
mysql 查询本周数据7天内的:
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怎么查询当前周的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于mysql查询本周数据、mysql怎么查询当前周的信息别忘了在本站进行查找喔 。

    推荐阅读