无法连接来自 Athena 中两个不同数据库的两个表

Unable to join two tables from two different databases in Athena

我在 Athena 中有 2 个数据库,每个数据库都有自己的 table。我不确定如何连接两个 table。Contractinfo_2019 是一个数据库,enrollmentinfo_2019 也是另一个数据库。我不断收到错误消息:

"SYNTAX_ERROR:第 11:10 行:Table awsdatacatalog.enrollmentinfo_2019.contractinfo2019 不存在

此查询 运行 针对 "enrollmentinfo_2019" 数据库,除非查询限定。请 post 我们论坛上的错误消息或使用查询 ID 联系客户支持:1bbc3941-4fa1-40a0-87c1-eb093784c990。

    SELECT a.*,
        b.*
FROM 
    (SELECT contract_id,
         plan_id,
         organization_type,
         plan_type,
         organization_name,
        plan_name,
        parent_organization
    FROM contractinfo2019) AS a
LEFT JOIN 
    (SELECT contract_number,
         plan_id,
        state,
        county,
        enrollment
    FROM enrollmentinfo2019) AS b
    ON a.contract_id=b.contract_number
        AND a.plan_id=b.plan_id 

谁能指导我如何加入 Athena 中的 table。我不确定我在这里做错了什么?

我建议使用 WITH

重写查询

例如:

 WITH a AS 

    (SELECT contract_id,
         plan_id,
         organization_type,
         plan_type,
         organization_name,
        plan_name,
        parent_organization
    FROM Contractinfo_2019.contractinfo2019),
b as 
    (SELECT contract_number,
         plan_id,
        state,
        county,
        enrollment
    FROM enrollmentinfo_2019.enrollmentinfo2019) 

SELECT * FROM a
LEFT JOIN b ON a.contract_id=b.contract_number
        AND a.plan_id=b.plan_id 

您只需要合格的 table 个名称。

而不是:

FROM contractinfo2019

使用这个(假设我有你的数据库并且 table 名字正确):

FROM contractinfo_2019.contractinfo2019