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这个排除功能呢(亲测没问题)
最新推荐文章于 2024-05-08 09:14:57 发布