连接两个(A,B)表(加入A的键:1行= 1个数据;加入B的键:1行=几个数据)

时间:2016-12-13 13:31:28

标签: sql join hive

我有2个表A和B.如何加入这两个表?

A

id  |group
6ZE |A
UZC |A
LQY |B
HO7 |B
V4P |C
KR0 |C

id                 |DATA
6ZE, FET, UZX      |50048
UZC, LQY           |89871
LQY, E03           |31579
HO7, 7KT, LXW, EK8 |17260
V4P, MKP, TPJ      |37344
KR0                |50044

4 个答案:

答案 0 :(得分:0)

试试这个

bList

答案 1 :(得分:0)

你可以试试......

select * from A, B where B.id like concat('%', A.id ,'%');

答案 2 :(得分:0)

DDL&安培; DML

          CREATE TABLE A_TABLE
          (ID VARCHAR2(50),GROUPP VARCHAR2(50))

          INSERT INTO A_TABLE(ID,GROUPP)VALUES('6ZE','A');
          INSERT INTO A_TABLE(ID,GROUPP)VALUES('UZC','A');
          INSERT INTO A_TABLE(ID,GROUPP)VALUES('LQY','B');
          INSERT INTO A_TABLE(ID,GROUPP)VALUES('HO7','B');
          INSERT INTO A_TABLE(ID,GROUPP)VALUES('V4P','C');
          INSERT INTO A_TABLE(ID,GROUPP)VALUES('KR0','C');
          COMMIT;

          CREATE TABLE B_TABLE
          (ID VARCHAR2(50),DATA VARCHAR2(50));


          INSERT INTO B_TABLE(ID,DATA)VALUES('6ZE, FET, UZX','50048');
          INSERT INTO B_TABLE(ID,DATA)VALUES('UZC, LQY','89871');
          INSERT INTO B_TABLE(ID,DATA)VALUES('LQY, E03','31579');
          INSERT INTO B_TABLE(ID,DATA)VALUES('HO7, 7KT, LXW, EK8','17260');
          INSERT INTO B_TABLE(ID,DATA)VALUES('V4P, MKP, TPJ','37344');
          INSERT INTO B_TABLE(ID,DATA)VALUES('KR0','50044');
          COMMIT;

并选择脚本

  SELECT A.ID,A.GROUPP,B.ID,B.DATA
              FROM
              A_TABLE A
              JOIN
              B_TABLE B
              ON B.ID LIKE '%'||A.ID||'%'

拆分不是常用功能

答案 3 :(得分:0)

SELECT *
FROM A_TABLE INNER JOIN B_TABLE ON FIND_IN_SET(A_TABLE.id, B_TABLE.id)