如何在Spark SQL中表示当前行和当前行+1

时间:2018-07-21 00:21:43

标签: apache-spark

我有一个希望将当前行与下一行求和的窗口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
----------------------------------------------------------------------------------------------------------------------------------------^^^

1 个答案:

答案 0 :(得分:1)

定义基于行的框架的正确语法是

ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING

类似

ROWS BETWEEN 1 PRECEDING AND CURRENT ROW 

您也可以用UNBOUNDED关键字替换数字常量。