【发布时间】:2021-06-03 12:24:27
【问题描述】:
我有一份所有消费者购买的清单,其中一些消费者在一段时间内进行了多次购买。我想用每个消费者第一次购买的位置填充一列,但我收到了这个错误:
Error in SQL statement: ParseException:
mismatched input '(' expecting <EOF>(line 2, pos 25)
== SQL ==
SELECT consumer_id
,location OVER(partition BY table.consumer_id) AS first_purchase_site
---------------------^^^
FROM table
为清楚起见,这是我的查询:
SELECT consumer_id
,location OVER(partition BY table.consumer_id) AS first_purchase_site
FROM table
WHERE consumer_purchase_order_sequence = 1
【问题讨论】:
-
你应该使用窗口函数spark.apache.org/docs/latest/…
-
partition by 与聚合函数一起使用。你不能使用
location over()。请使用这个SELECT consumer_id ,location from ( SELECT a.*, row_number() OVER(partition BY table.consumer_id) AS rn from Table a) rs WHERE rs.rn=1
标签: sql apache-spark hive alias partition-by