我想写一个查询,它给出从昨天开始的最后 14 天的 DATES 列。
例子:
Dates
2012-06-21
2012-06-20
2012-06-19
--
-
我想写一个查询,它给出从昨天开始的最后 14 天的 DATES 列。
例子:
Dates
2012-06-21
2012-06-20
2012-06-19
--
-
;WITH n(n) AS
(
SELECT TOP (14) ROW_NUMBER() OVER (ORDER BY [object_id])
FROM sys.objects ORDER BY [object_id]
)
SELECT Dates = DATEADD(DAY, -n, DATEDIFF(DAY, 0, GETDATE())) FROM n
ORDER BY n;
其他方式;
;with days(day) as
(
select getdate() - 1 as day
union all
select day - 1
from days
where day > dateadd(day, -14, getdate())
)
select cast(day as date) from days