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 '|';
[color=red][b]测试表a中数据如下:[/b][/color]
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
[color=red][b]测试表b中数据如下:[/b][/color]
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
[color=red][b]测试表b中分区数据如下: [/b][/color]
hive> select * from b where day='01';
OK
130 a 01
131 b 01
132 c 01
Time taken: 0.359 seconds
[color=red][b]测试表b中分区数据如下: [/b][/color]
hive> select * from b where day='02';
OK
133 02
134 02
135 02
Time taken: 0.187 seconds
测试语句如下:
[color=red][b]1.左连接不指定条件 [/b][/color]
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
[color=red][b]2.左连接指定连接条件(on中) [/b][/color]
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
[color=red][b]3.左连接指定连接条件(on外) [/b][/color]
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