欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-19 14:23:04
查询当前这周的数据 select name,submittime from enterprise where yearweek(date_format(submittime...
查询当前这周的数据
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 下月第一天