mysql查询本周、上周、本月、上个月份数据的sql代码

本周

where yearweek(date_format(字段名,'%Y-%m-%d'))=yearweek(now())

上周

where yearweek(date_format('字段名','%Y-%m-%d'))= yearweek(now())-1

本月

where date_format('字段名','%Y-%m')=date(now(),'%Y-%m')

上月

where date_format('字段名','%Y-%m')= date_format(date_sub(curdate(),interval 1 month),'%Y-%m')

前6个月

where date_format('字段名','%Y-%m') between date_format(date_sub(now(),interval 6 month),'%Y-%m') and now()

 

 

更多做法

http://linkyou.blog.51cto.com/1332494/751980/

posted @ 2016-04-21 18:19  rcj_飞翔  阅读(97)  评论(0)    收藏  举报