2017-05-25 112 views
1

假设:该值tbl_A栏中加入上具有不同的长度:5个10 值在tbl_B的列加盟on是较大的长度,当根据tble_A中值的长度应用substr()时应用。 所以我尝试使用HiveQL连接表时适用于“ON”条款的情况下发言,我得到以下错误:条件加入使用case语句“上”子句中HiveQL

Error while compiling statement: FAILED: SemanticException [Error 10017]: Line 22:3 Both left and right aliases encountered in JOIN '11'

这里是我的代码:

select 
a.fullname, b.birthdate 
from mydb.tbl_A a 
left join mydb.tbl_B b 
on a.fullname = 
    case when length(a.fullname) = 5 then substr(b.othername,1,5) 
    when length(a.fullname)= 9 then substr(b.othername, 8, 9) end 
and a.birthdate = b.birthdate 

我做不到找到这方面的很多信息。您的帮助将不胜感激。谢谢。

回答

0

JOIN目前有一些限制。
这是一个解决方法。

select a.fullname 
     ,b.birthdate 

from    tbl_A a 

     left join tbl_B b 

     on   a.fullname = 
        substr(b.othername,1,5) 

       and a.birthdate = 
        b.birthdate 

where length(a.fullname) <> 9 
    or a.fullname is null 

union all 

select a.fullname 
     ,b.birthdate 

from    tbl_A a 

     left join tbl_B b 

     on   a.fullname = 
        substr(b.othername,8,9) 

       and a.birthdate = 
        b.birthdate 

where length(a.fullname) = 9