当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL查询本周、上周、本月、上个月份数据的sql代码

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
查询当前这周的数据
select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now());

查询上周的数据
select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())-1;

查询当前月份的数据
select name,submittime from enterprise where date_format(submittime,'%y-%m')=date_format(now(),'%y-%m')

查询距离当前现在6个月的数据
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();

查询上个月的数据
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 下月第一天

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网