开发者

Retrieve last two week's data from MYSQL excluding this week

i am looking to retrieve last two week's data from MYSQL excluding this week's data.

for example if today is mon - friday, query should return previous two weeks record. if today is either saturday or sunday, query should return records for this week + last week's records.

did some search on and found that YEARweek cou开发者_高级运维ld be useful but couldn't find the way to implement.


If you don't have records on Saturday and Sunday. This should works fine.

where case 
when weekday(now()) between 0 and 4 then 
record_date between date_sub( date_sub(now(),INTERVAL weekday(now())+1 day),INTERVAL 2 WEEK) and  date_sub(now(),INTERVAL weekday(now())+1 day)
else
record_date between date_sub(now(),INTERVAL 2 WEEK) and  now()
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜