hive如何处理not in和in的问题

    首先我们先创建两个表和测试数据。建表语句如下:

create table table1(uid STRING, dayTimes BIGINT) PARTITIONED BY (dt STRING);
create table table2(uid STRING, monTimes BIGINT) PARTITIONED BY (dt STRING);
insert into table table1 partition(dt='2014') values ('1', 100),('2', 102),('4',20);
insert into table table2 partition(dt='2014') values ('1', 500),('2', 612),('3',150);

    in查询方式。

select t1.uid, t1.dayTimes, t2.monTimes from table1 t1 
    left outer join table2 t2 on(t1.uid = t2.uid and t2.dt = '2014') 
where t1.dt = '2014' and t2.uid is not null;

    查询结果:

1       100     500
2       102     612

    not in查询方式。

select t1.uid, t1.dayTimes, t2.monTimes from table1 t1 
    left outer join table2 t2 on(t1.uid = t2.uid and t2.dt = '2014') 
where t1.dt = '2014' and t2.uid is null;

    查询结果:

4       20      NULL

    有兴趣的可以亲自测试一下,如有不当,请指正。

转载于:https://my.oschina.net/u/561917/blog/667422

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值