SQL语句怎么查出上一周和上一月的记录

如题所述

---查上周记录 select * from 你的表 where 你的日期字段 between dateadd(d,-7,getdate()) and getdate() --查上月记录 select * from 你的表 where convert(varchar(4),year(你的日期字段))+convert(varchar(2),month(你的日期字段))= convert(varchar(4),year(getdate()))+convert(varchar(2),month(getdate()))
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-10-06
上一周
select * from table_a where col_date between next_day(sysdate,'Monday') - 7 and next_day(sysdate,'Sunday') -7

上一个月:
select * from table_a where col_date between last_day(add_months(sysdate-2))+1 and
last_day(add_months(sysdate,-1))
相似回答