如何在配置单元中进行条件连接

fxnxkyjh  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(218)

我有两个配置单元表,我只想在两个表中都有数据的情况下进行连接。如果其中一个表为空,我不希望发生连接。我试着探索案例陈述的意图是

select count(*) as val 
case
 when val > 0 then <do join of table1 and table2 here>
 else
   <do nothing>
end
from table2

但是,看起来hive不允许在case语句中执行求值,所以这种方法不起作用。任何人都对如何在Hive中执行此操作有任何意见。

xn1cxnb4

xn1cxnb41#

select *
from TableA as a
left join TableB as b
on b.A_Id = a.A_Id
where
    b.A_Id is not null or
    not exists (select top 1 A_Id from TableB)

这是我遇到的来源。

相关问题