我想写一个查询,其中列出了过去14天的DATES列 从昨天开始。
示例:
Dates
2012-06-21
2012-06-20
2012-06-19
--
-
答案 0 :(得分:4)
;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;
答案 1 :(得分:0)
另一种方式;
;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