我有一个希望将当前行与下一行求和的窗口sql,因此我编写了以下sql:
select depName, empNo, salary, sum(salary) over (partition by depName order by empNo rows between CURRENT ROW AND CURRENT ROW + 1) sum_salary from t
但是其中存在语法错误
org.apache.spark.sql.catalyst.parser.ParseException:
missing ')' at '+'(line 2, pos 136)
== SQL ==
select depName, empNo, salary, sum(salary) over (partition by depName order by empNo rows between CURRENT ROW AND CURRENT ROW + 1) sum_salary from t
----------------------------------------------------------------------------------------------------------------------------------------^^^
答案 0 :(得分:1)
定义基于行的框架的正确语法是
ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING
类似
ROWS BETWEEN 1 PRECEDING AND CURRENT ROW
您也可以用UNBOUNDED
关键字替换数字常量。