Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用NOT IN子句替代配置单元查询_Sql_Hive_Hiveql_Notin - Fatal编程技术网

Sql 使用NOT IN子句替代配置单元查询

Sql 使用NOT IN子句替代配置单元查询,sql,hive,hiveql,notin,Sql,Hive,Hiveql,Notin,我有以下一组配置单元表: 创建表映像\u添加 客户id字符串, 图像_键字符串, 图像大小字符串 ; 创建表映像\u删除 客户id字符串, 图像_键字符串, 图像大小字符串 ; 创建存储的表映像 客户id字符串, 图像_键字符串, 图像大小字符串 ; 我想从一个查询运行一个insert,如下所示: 插入存储的图像 选择ia.customer\u id, ia.image_键, 图像大小 从图像! 其中ia.image\u键不在 从图像移除ir中选择ir.image\u键; 这会产生笛卡尔积,而h

我有以下一组配置单元表:

创建表映像\u添加 客户id字符串, 图像_键字符串, 图像大小字符串 ; 创建表映像\u删除 客户id字符串, 图像_键字符串, 图像大小字符串 ; 创建存储的表映像 客户id字符串, 图像_键字符串, 图像大小字符串 ; 我想从一个查询运行一个insert,如下所示:

插入存储的图像 选择ia.customer\u id, ia.image_键, 图像大小 从图像! 其中ia.image\u键不在 从图像移除ir中选择ir.image\u键; 这会产生笛卡尔积,而hive不允许我运行它。
如何使用另一个查询实现这一点?

使用left join+where为null

insert into images_stored
select ia.customer_id, 
       ia.image_key, 
       ia.image_size 
from image_additions ia 
     left join image_removals ir on ia.image_key=ir.image_key 
where ir.image_key is null;
使用不存在:

insert into images_stored
select ia.customer_id, 
       ia.image_key, 
       ia.image_size 
from image_additions ia  
where not exists (select 1 from image_removals ir where ia.image_key=ir.image_key);

可能重复:可能重复:是的,简单的左键连接和空查询是否左键连接还有您的名字,nice Dog尝试了这两种方法,并且它们花费了大约相同的时间。非常感谢你的帮助。