请帮我解决一下问题:
我需要在任何月份的选择中持续3个月
例如:如果我选择 7月 2015,那么我需要几个月 06,05,04
答案 0 :(得分:0)
SELECT *
FROM TABLE_NAME
WHERE Date_Column >= DATEADD(MONTH, -3, GETDATE())
答案 1 :(得分:0)
--set @Input_Date as 07-01-2015 for July 2015
Declare @Input_Date Date
SELECT *
FROM TABLE_NAME
WHERE cast(Date_Column as date) >= cast(DATEADD(MONTH, -3,@Input_Date) as date) and cast(Date_Column as date) <=@Input_Date
--cast to date is purposely done to avoid comparision issues for time part