我试图将3个月的净值与一个月的净值相加。代码
SELECT [CMONTH]
,[ID]
,[NET_VALUE_1M]
,SUM(CAST([NET_VALUE_1M] as float)) OVER
(PARTITION BY [ID] ORDER BY [CMONTH]
ROWS BETWEEN 3 FOLLOWING AND CURRENT ROW) as 'NET_VALUE_3M'
FROM [Channel_AGG]
正在触发错误
Msg 4193, Level 16, State 4, Line 2
'BETWEEN ... FOLLOWING AND CURRENT ROW' is not a valid window frame
and cannot be used with the OVER clause.
为什么,造成这种情况的原因以及如何解决?
答案 0 :(得分:3)
您需要使用
ROWS BETWEEN CURRENT ROW AND 3 FOLLOWING