我在SQL Server中需要一个WHERE条件,我可以从给定日期返回过去7天的活动。
假装我有2列日期[dateA]和[dateB]
我正在寻找像
这样的东西SELECT *
FROM TABLE
WHERE [dateB] >= ([dateA] - 7 days)
答案 0 :(得分:2)
WHERE dateB >= DATEADD(DAY, -7, dateA)
答案 1 :(得分:1)
select * from table
where dateB >= dateadd(dd,-7, dateA)
答案 2 :(得分:0)
SELECT * FROM TABLE WHERE [dateB])> = convert(datetime,[dateA] - 7)
你是如此亲密
答案 3 :(得分: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 )