SQL Server错误:“BETWEEN…FOLLOWING AND CURRENT ROW”不是一个有效的窗口框架,不能与OVER子句一起使用。

时间:2022-09-03 15:30:25

I am trying to sum 3 months' net value with the one months' net values. The code

我想把3个月的净值和1个月的净值相加。的代码

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]

is firing the error

是射击误差

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.

Why, what is causing this and how to solve it?

为什么,是什么导致了这个,怎么解决呢?

1 个解决方案

#1


3  

You need to use

您需要使用

ROWS BETWEEN CURRENT ROW AND 3 FOLLOWING

The upper bound cannot be smaller than the lower bound.

上界不能小于下界。

#1


3  

You need to use

您需要使用

ROWS BETWEEN CURRENT ROW AND 3 FOLLOWING

The upper bound cannot be smaller than the lower bound.

上界不能小于下界。