2019独角兽企业重金招聘Python工程师标准>>>
首先我们先创建两个表和测试数据。建表语句如下:
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
有兴趣的可以亲自测试一下,如有不当,请指正。