问题描述
此查询在 Redshift 中有效,但在 Amazon Athena 中无效:
SELECT disTINCT t1.place_id,t1.date,flg
FROM rec t1
LEFT JOIN (
SELECT date,place_id,CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END AS flg
FROM rec
GROUP BY date,place_id
) t2 ON t1.one_year_ago_dow_day = t2.date AND t1.place_id = t2.place_id
错误信息是:
------------------------------------------
Your query has the following error(s):
Syntax_ERROR: line 84:39: Column 't2.date' cannot be resolved
This query ran against the "~~~" database,unless qualified by the query. Please post the error message on our forum or contact customer support with Query Id: 29311d73-2cdb-4279-b88c-xxxxxxx
--------------------------------------
错误说“t2.date”是问题所在,是不是因为我在左连接中选择了表?
如何让这个 sql 在 Athena 中工作?
任何见解将不胜感激。
解决方法
如果 date
字段导致问题(如@Deepstop 所建议),您可以尝试:
SELECT DISTINCT t1.place_id,t1.date,flg
FROM rec t1
LEFT JOIN (
SELECT
date as date1,-- Changed here,and in the ON below
place_id,CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END AS flg
FROM rec
GROUP BY date,place_id
) t2 ON (t1.one_year_ago_dow_day = t2.date1) AND (t1.place_id = t2.place_id)