0

我正在尝试使用 LAG 和 LEAD 函数从列中选择领先和滞后值。下面是表格和数据。

hive> select * from foo;                                                      
OK
a
1
2
3
4
5
6
7
8
9
Time taken: 0.923 seconds

当我尝试选择领先和滞后值时,会抛出以下错误。

hive> select LAG(a, 1) over (order by a) as previous, a, LEAD(a, 1) over (order by a) as next from foo;
FAILED: ParseException line 1:22 missing FROM at '(' near '(' in subquery source
line 1:23 cannot recognize input near 'order' 'by' 'a' in subquery source

如何解决tis问题?

4

1 回答 1

0

我可以看到语句中缺少“分区依据”子句。

选择lead(a,1) over (partition by a order by a) as next from foo;

仅在表中的一列上运行是没有用的,如果您有更多列,例如日期/时间、类别,它将起作用。

于 2016-05-13T22:38:43.723 回答