配置单元中的条件连接

ecr0jaav  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(326)

我想在配置单元中执行以下查询-

select * from supp a inner join trd_acct b
on
(a.btch_id = 11170 AND a.btch_id = b.btch_id)
OR (a.btch_id = 11164 AND a.supp_id = b.supp_id)

但是得到错误-
失败:semanticexception[error 10019]:行3:1或在当前“supp\u id”的联接中不受支持

yfjy0ee7

yfjy0ee71#

下面的查询在hive(hadoop)中运行良好-

select * from supp a inner join trd_acct b
where
(a.btch_id = 11170 AND a.btch_id = b.btch_id)
OR (a.btch_id = 11164 AND a.supp_id = b.supp_id)

我在Hive控制台中进行了测试。

cs7cruho

cs7cruho2#

你可以用 UNION :

select * from supp a inner join trd_acct b
 on a.btch_id = 11170 AND a.btch_id = b.btch_id
UNION ALL
select * from supp a inner join trd_acct b
 on a.btch_id = 11164 AND a.supp_id = b.supp_id

或者你可以试试 CASE EXPRESSION :

select * from supp a
inner join trd_acct b
 on CASE WHEN a.btch_id = 11164 THEN a.supp_id 
         WHEN a.btch_id = 11170 THEN a.btch_id END
  = CASE WHEN a.btch_id = 11164 THEN b.supp_id
         WHEN a.btch_id = 11170 then b.btch_id END

相关问题