在Hive中联接3个表-ParseException在'<EOF>'附近的无关输入'_SYNTHJOIN_expecting)

时间:2019-08-17 21:52:41

标签: sql hive hiveql

我想加入3张桌子,

摘要

dept_cd | call_dt |  cust_id | hold_time | talk_time |  work_time | call_cd

通话

cust_id | call_count | agent_length

类别

cust_id | call_type |  call_category |  call_start_dt | agent_cd | agent_cd

这就是我想要的输出表,

输出

call_date |sum(talk_time)| sum(work_time)| sum(hold_time)| dept_cd| sum(call_count)| call_type|call_category| call_start_date 

如果仅连接汇总表和调用表,则代码有效,当我添加第三个表时,我会收到parseexception错误

这是我的代码,

select
    SU.call_dt,
    SU.dep_code,
    CG.call_type,
    CG.call_category,
    CG.call_start_dt,
    sum(SU.hold_time) as sum_hold,
    sum(SU.talk_time) as sum_talk,
    sum(SU.work_time) as sum_work,
    sum(CA.call_count)as sum_calls
from summary SU
    inner join 
        (select distinct cust_id, call_count from calls) CA on SU.cust_id = CA.cust_id
    inner join 
        (select call_type,call_category,cust_id,call_start_dt from category) CG on SU.cust_id = CG.cust_id
where 
    CG.call_start_dt between '2019-07-01' and '2019-07-31'
    and SU.call_dt between '2019-07-01' and '2019-07-31'
group by
    SU.call_dt,
    SU.dep_code,
    CG.call_type,
    CG.call_category,
    CG.call_start_dt;

Am在使用“ SUM”的列中收到以下错误。

编译语句时出错:

  

失败:ParseException行1:808外来输入'_SYNTHJOIN_4324cda7___Stalk_time_'期望)位于”附近   行1:918多余的输入'_SYNTHJOIN_4324cda7___Shold_time_'期望)靠近''   线1:1028外来输入'_SYNTHJOIN_4324cda7___Swork_time_'期望)靠近''

我该如何解决?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我看不到需要子查询。这是您想要的吗?

from summary SU inner join 
     (select distinct cust_id, call_count
      from calls
     ) CA
     on SU.cust_id = CA.cust_id inner join 
     from category CG
     on SU.cust_id = CG.cust_id

名为cust_id的表中名为category的列是可疑的。我希望join会更像category_id之类的东西。