更新时间:2023-01-29 17:12:51
您为 ROWS/RANGE 找到的文档不适用于 SQL Server 2008 - 它适用于 SQL Server 的未来版本.
The documentation you found for ROWS/RANGE is not for SQL Server 2008 - it's for a future version of SQL Server.
要在 SQL 2008 中完成查询,一种方法类似于:
To accomplish your query in SQL 2008, one approach would be similar to:
SELECT a.TIC, a.datadate, a.effdate, x.s
FROM quarterResults a
CROSS APPLY ( SELECT ISNULL(SUM(v), 0)
FROM ( SELECT TOP(4) b.valuei
FROM quarterResults b
WHERE b.datadate < a.datadate
ORDER BY b.datadate DESC ) x(v)
) x(s)
ORDER BY a.TIC, a.datadate
请注意,这可能是一个开销很大的查询.将 OVER 表达式与 ROWS 一起使用可能会更有效,但同样,它在 SQL Server 2008 中不可用.
Note that this is potentially an expensive query. The use of the OVER expression with ROWS would probably be more efficient but, again, it is not available in SQL Server 2008.