问题描述
我试图通过检查where子句中的两个子查询表达式来创建表,但是查询失败并显示以下错误:
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子句中仅使用一个子查询执行同一命令,则该命令将成功执行。话虽如此,是否有其他选择可以通过不同的方式实现相同目标?
解决方法
当然。您可以使用左联接。 内部联接将作为现有联接。和左连接+ 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