3

我需要 SQL Server 中的 WHERE 条件,我可以从给定日期返回过去 7 天的活动。

假装我有 2 列日期 [dateA] 和 [dateB]

我正在寻找类似的东西

SELECT *
FROM TABLE
WHERE [dateB] >= ([dateA] - 7 days)
4

4 回答 4

3
WHERE dateB >= DATEADD(DAY, -7, dateA)

潜在有用的阅读...

于 2013-10-04T18:00:30.130 回答
1
select * from table
where dateB >= dateadd(dd,-7, dateA)
于 2013-10-04T18:04:03.930 回答
0

从表中选择 * [dateB]) >= convert(datetime,[dateA] - 7)

你是如此亲近

于 2013-10-04T18:05:29.117 回答
0
    IF you need past 7 days activity then you need take difference of date in that column from today i.e GETDATE() it will be something like this......

 WHERE (DATEDIFF(DAY, GETDATE(), dateA) <= 0 AND DATEDIFF(DAY, GETDATE(), dateA) > -7 ) 
        AND (DATEDIFF(DAY, GETDATE(), dateB) <= 0 AND DATEDIFF(DAY, GETDATE(), dateB) > -7 )
于 2013-10-04T19:11:37.420 回答