日期:2014-05-18  浏览次数:20394 次

查询一周内的数据
表1

id name time
1 发哥 2012-05-29 09:33:13
2 春哥 2012-05-30 09:40:13
3 曾哥 2012-06-01 09:12:13

今天是6月6号 要查询从6月6号开始往前7天内的数据

结果应该是
 
2 春哥 2012-05-30 09:40:13
3 曾哥 2012-06-01 09:12:13


SQL code

select * from 表1 where datediff(wk,time,getdate()) <= 7


这样写不对 会全部查出来



------解决方案--------------------
SQL code

select * from 表1 where datediff(dd,time,getdate()) <= 7

------解决方案--------------------
select * from 表1 where time >= dateadd(day,-7,getdate())