Hive左连接

CREATE EXTERNAL TABLE IF NOT EXISTS a(
telno STRING,
other STRING
)
PARTITIONED BY(day String)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|';

CREATE EXTERNAL TABLE IF NOT EXISTS b(
telno STRING,
other STRING
)
PARTITIONED BY(day String)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|';


测试表a中数据如下:
hive> select * from a;
OK
130 a 01
131 b 01
132 c 01
133 d 01
134 e 01
135 f 01
Time taken: 0.215 seconds

测试表btable中数据如下:
hive> select * from b;
OK
130 a 01
131 b 01
132 c 01
133 02
134 02
135 02
Time taken: 0.281 seconds

测试表btable中分区数据如下:
hive> select * from b where day='01';
OK
130 a 01
131 b 01
132 c 01
Time taken: 0.359 seconds

测试表btable中分区数据如下:
hive> select * from b where day='02';
OK
133 02
134 02
135 02
Time taken: 0.187 seconds

测试语句如下:
1.左连接不指定条件
hive> select a.telno,b.other,a.day,b.day from a left outer join b on(a.telno=b.telno) ;
OK
130 a 01 01
131 b 01 01
132 c 01 01
133 01 02
134 01 02
135 01 02
Time taken: 8.935 seconds

2.左连接指定连接条件(on中)
hive> select a.telno,b.telno,b.other,a.day,b.day from a left outer join b on(a.telno=b.telno and b.day='02');
OK
130 NULL NULL 01 NULL
131 NULL NULL 01 NULL
132 NULL NULL 01 NULL
133 133 01 02
134 134 01 02
135 135 01 02
Time taken: 12.624 seconds

3.左连接指定连接条件(on外)
hive> select a.telno,b.telno,b.other,a.day,b.day from a left outer join b on(a.telno=b.telno ) where b.day='02';
OK
133 133 01 02
134 134 01 02
135 135 01 02
Time taken: 8.88 seconds

你可能感兴趣的:(hive)