Hive-where子句失败的多个子查询

时间:2020-10-15 19:21:38

标签: hive hiveql

我试图通过检查where子句中的两个子查询表达式来创建表,但是查询失败并显示以下错误:

不支持的子查询表达式。只有1个子查询表达式是 支持

代码段如下(不是确切的代码。只是为了更好地理解):

Create table winners row format delimited fields terminated by '|' as
select
  games,
  players
from olympics
where
exists (select 1 from dom_sports where dom_sports.players = olympics.players)
and not exists (select 1 from dom_sports where dom_sports.games = olympics.games)

如果我在where子句中仅使用一个子查询执行同一命令,则该命令将成功执行。话虽如此,是否有其他选择可以通过不同的方式实现相同目标?

1 个答案:

答案 0 :(得分:0)

当然。您可以使用左联接。 内部联接将作为现有联接。和左连接+ where子句将模仿不存在。 粒度可能存在问题,但这取决于您的数据。

select distinct 
  olympics.games,
  olympics.players
from olympics
inner join  dom_sports dom_sports  on dom_sports.players = olympics.players 
left join dom_sports dom_sports2 where dom_sports2.games = olympics.games
where dom_sports2.games is null 
相关问题