目前我的查询正在获取从当前日期到过去 7 天的数据。我想从上周获取数据。意思是如果今天是 2013-06-20,那么数据应该从上周(2013-06-10 到 2013-06)获取-16)。我搜索了许多论坛的确切答案,但仍然无法找到。
这是我的查询
SELECT CONVERT(varchar(25),PostDate,107) AS duration, count(*) AS posts
FROM MDBDetails WHERE
DateAdd(dd, 0, DateDiff(dd, 0, PostDate)) <= DateAdd(dd, 0, DateDiff(dd, 0, GETDATE())) AND
DateAdd(dd, 0, DateDiff(dd, 0, PostDate)) >= DateAdd(dd, 0, DateDiff(dd, 0, GETDATE())) - 7
GROUP BY CONVERT(varchar(25),PostDate,107)
ORDER BY duration