[英]ROWS BETWEEN function in SQL Server 2014
Not sure why I'm getting this error. 不知道为什么我得到这个错误。
Query: 查询:
SELECT
TURBINE, YR, MO, D,
AVG(Z_SCORE) OVER (PARTITION BY TURBINE ORDER BY ROWNO ROWS BETWEEN 13 PRECEDING AND CURRENT ROW) AS ROLLINGAVG
FROM
#ORDERED
Sample Data 样本数据
Rowno Turbine Yr Mo D Z_Score
--------------------------------------------------------
5153 KV#G04_25 2016 5 27 0.530932540472319
5154 KV#I11_47 2016 5 27 -0.0887050712447865
5155 KV#B04_08 2016 5 27 0.983732236771842
5156 KV#B05_09 2016 5 27 0.0127747723017027
ERROR: 错误:
Msg 102, Level 15, State 1, Line 75 Msg 102,第15层,州1,第75行
Incorrect syntax near 'ROWS' “ ROWS”附近的语法不正确
Most errors regarding this error are about using an older version of SQL Server but I'm using 2014. ROWS should work fine. 有关此错误的大多数错误都与使用旧版本的SQL Server有关,但我正在使用2014。ROWS应该可以正常工作。
I've also tried this without the partition by and used a group by instead. 我也尝试过在没有分区的情况下使用,而是使用group by。 That also didn't work. 那也没有用。 Any time there's "OVER" and "ROWS" I get an error. 每当出现“ OVER”和“ ROWS”时,我都会报错。
The code looks good to me, are you working on a database in a Pre 2012 compatibility level? 该代码对我来说看起来不错,您是否正在使用Pre 2012兼容级别的数据库? not all functionality is avilable in older versions of SQL Server 并非所有功能在旧版本的SQL Server中都可用
The query worked for me in SQL Server 2016 with the sample data provided. 该查询在SQL Server 2016中为我提供了示例数据。
SELECT TURBINE
, YR
, MO
, D
, AVG(Z_SCORE) OVER ( PARTITION BY TURBINE ORDER BY ROWNO ROWS BETWEEN 13 PRECEDING AND CURRENT ROW ) AS ROLLINGAVG
FROM #ORDERED;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.