首先咱們先建立兩個表和測試數據。建表語句以下:sql
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查詢方式。shell
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查詢方式。ui
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;
查詢結果:
code
4 20 NULL
有興趣的能夠親自測試一下,若有不當,請指正。
it