• Hive--关联表(join)


    在hive中,关联有4种方式

    • 内关联:join on
    • 左外关联:left join on
    • 右外关联:right join on
    • 全外关联:full join on

    另外还有一种可实现hive笛卡儿积的效果(hive不支持笛卡儿积): 在on后面接为true的表达式,如on 1=1(需先设置非严格模式:set hive.mapred.mode=nonstrict);

    详细操作和结果如下:

    如我有两个表:join1和join2,如下

    内关联:select * from jion1 join join2 on jion1.id = jion2.id;

    • 作用:将表1和表2的字段id相同的内容 关联到一个表里。
    • 效果如下:

     

    左外连接:select * from jion1 left join join2 on jion1.id = jion2.id;

    • 作用:以join左边的表为标准进行连接(即保留左边表的字段值,右边表不符合on条件的用null表示)。
    • 效果如下:

     

    右外连接:select * from jion1 right join join2 on jion1.id = jion2.id;

    • 作用:以join右边的表为标准进行连接(即保留右边表的字段值,左边表不符合on条件的用null表示)。
    • 效果如下:

    全外连接:select * from jion1 full join join2 on jion1.id = jion2.id;

    • 作用:两个表连接,表留所有字段的值,不符合on条件的用null表示。
    • 效果如下:

     

    hive的”笛卡儿积“:select * from join1 join join2 on 1=1;

  • 相关阅读:
    centos8.0 安装 jenkins
    No match for argument: mysql-community-server Error: Unable to find a match: mysql-community-server
    Navicat 远程连接 centos8.0
    centos8.0 安装 mysql
    -bash: java-version: command not found
    centos8.0 安装 JDK1.8
    [Err] 1062
    android之Fragment基础详解(一)
    Android之RecyclerView(一)
    Android之ProgressBar
  • 原文地址:https://www.cnblogs.com/yiwanfan/p/9628235.html
Copyright © 2020-2023  润新知