Hive結合の使用の概要

ハイブ結合モードの概要

結合タイプ

[INNER] JOIN内部結合
LEFTJOIN左結合
RIGHTJOIN右結合
FULLOUTERJOINすべて外部結合
LEFTSEMIJOIN左半分
結合CROSSJOINDescartes

ここに画像の説明を挿入

データの準備

  • cl_tmp.tmp_tm_join_testA
id 名前
1 張三豊
2 Li Si
3 王呉
  • cl_tmp.tmp_tm_join_testB
id 年齢
2 26
3 28
4 29
create table cl_tmp.tmp_tm_join_testA(id int,name string);
insert INTO cl_tmp.tmp_tm_join_testA values(1,'张三'),(2,'李四'),(3,'王五');


create table cl_tmp.tmp_tm_join_testB(id int,age int);
insert INTO cl_tmp.tmp_tm_join_testB values(2,26),(3,28),(4,29);

データの関連付け

  • 内部結合
# 取 a b 表交集
select * from cl_tmp.tmp_tm_join_testA a INNER JOIN  cl_tmp.tmp_tm_join_testB b ON a.id = b.id;

ここに画像の説明を挿入

  • 左結合
# 补充a表中b表列值
select * from cl_tmp.tmp_tm_join_testA a LEFT JOIN  cl_tmp.tmp_tm_join_testB b ON a.id = b.id;

ここに画像の説明を挿入

# 获取a表中存在,b表中不存在
select * from cl_tmp.tmp_tm_join_testA a LEFT JOIN  cl_tmp.tmp_tm_join_testB b ON a.id = b.id where b.id is null;

ここに画像の説明を挿入

  • 右結合
# 获取b表数据
select * from cl_tmp.tmp_tm_join_testA a RIGHT JOIN  cl_tmp.tmp_tm_join_testB b ON a.id = b.id;

ここに画像の説明を挿入

# 获取b表中存在,a表中不存在的数据: b - a
select * from cl_tmp.tmp_tm_join_testA a RIGHT JOIN  cl_tmp.tmp_tm_join_testB b ON a.id = b.id where a.id is null;

ここに画像の説明を挿入

  • FULL [OUTER] JOIN
# a表∪b表
select * from cl_tmp.tmp_tm_join_testA a FULL OUTER JOIN  cl_tmp.tmp_tm_join_testB b ON a.id = b.id;

ここに画像の説明を挿入

# (a - b) ∪ (b - a) 
select * from cl_tmp.tmp_tm_join_testA a FULL OUTER JOIN  cl_tmp.tmp_tm_join_testB b ON a.id = b.id 
where a.id is null or b.id is null ;
  • 左半結合
# 同INNER JOIN  
select * from cl_tmp.tmp_tm_join_testA a LEFT SEMI JOIN cl_tmp.tmp_tm_join_testB b ON a.id = b.id;

ここに画像の説明を挿入

  • クロス結合
# 笛卡尔集
select * from cl_tmp.tmp_tm_join_testA a CROSS JOIN cl_tmp.tmp_tm_join_testB b ;

ここに画像の説明を挿入
リファレンスブログ

Hiveでのさまざまな参加関係と使用法https://blog.csdn.net/leying521/article/details/93197951

おすすめ

転載: blog.csdn.net/dbc_zt/article/details/110230658