我尝试在sql
控制台中执行此BigQuery
语句但是我收到如下错误。
有人可以就此提出建议吗?
"Error: Encountered " "OVER" "OVER "" at line 5, column 99. Was expecting: "END" ..."
SELECT *
FROM (SELECT
*
, CASE
WHEN initiator in ('01_User') THEN RANK() OVER (PARTITION BY item_id, log_date_desc, type ORDER BY log_date_desc DESC)
ELSE RANK() OVER (PARTITION BY item_id, log_date_desc ORDER BY log_date_desc DESC)
END AS ord
FROM temp.step1_itemlogall
) AS t
WHERE ord = 1
感谢。
答案 0 :(得分:4)
我认为问题在于将分析函数放在CASE语句中。您可以将其重写为计算这两个函数的内部选择,然后在外部查询中选择正确的函数。例如:
SELECT *
FROM (
SELECT
CASE WHEN initiator IN ('01_User')
THEN ord1
ELSE ord2
END AS ord
FROM (
SELECT *,
RANK() OVER (PARTITION BY item_id, log_date_desc, type
ORDER BY log_date_desc DESC) as ord1,
RANK() OVER (PARTITION BY item_id, log_date_desc
ORDER BY log_date_desc DESC) as ord2
FROM temp.step1_itemlogall))
WHERE ord = 1
我认为该错误消息的真实解释是:https://www.youtube.com/watch?v=2OBZf0QdKdE
答案 1 :(得分:0)
在用户界面或API调用中切换到标准SQL,只有旧版SQL引擎会引发此错误。