1.Hive Sql 不支持 Except 函数
2.我们使用LEFT OUTER JOIN + 字段 IS NULL 来实现,两个表的排除效果
3.先建两个表
create table person1 (name string,age int)
create table person2 (name string,age int)
4.插入数据,这里插入的是两个表中有相交的数据
insert into table test.person1 values(‘曹操’,20);
insert into table test.person1 values(‘郭嘉’,20);
insert into table test.person1 values(‘典韦’,20);
insert into table test.person1 values(‘张辽’,20);
insert into table test.person1 values(‘孙权’,20);
insert into table test.person1 values(‘周瑜’,20);
insert into table test.person2 values(‘刘备’,20);
insert into table test.person2 values(‘关羽’,20);
insert into table test.person2 values(‘张飞’,20);
insert into table test.person2 values(‘赵云’,20);
insert into table test.person2 values(‘孙权’,20);
insert into table test.person2 values(‘周瑜’,20);
5.使用
select a.name,a.age from test.person1 a left outer join test.person2 b on (b.name=a.name) where b.name is null

最后的执行结果,有没有达到你想要的的结果呢···
hive中没有except,那么怎么实现sql中except这个排除功能呢(亲测没问题)
最新推荐文章于 2026-07-02 15:11:33 发布
本文介绍HiveSQL不支持Except函数的情况下,如何通过LEFT OUTER JOIN及IS NULL条件实现两个表的差集运算。通过创建两个示例表并插入部分重叠数据,演示了具体操作步骤,最终达到类似Except的效果。
890

被折叠的 条评论
为什么被折叠?



