【问题标题】:How to write hive ql query to combine columns from 2 tables?如何编写配置单元 ql 查询以组合来自 2 个表的列?
【发布时间】:2013-11-11 17:52:32
【问题描述】:

我有 2 个与

架构相同的表
table1/table2 comprises of columns item_name and item_qty, sample data looks like

table1 中的示例数据

item_name    item_qty
item_0001    3
item_0002    7
item_0003    5
item_0004    4

table2 中的示例数据

item_name    item_qty
item_0003    15
item_0004    2

现在我需要按照此处的描述合并这两个表

Sample data in output
item_name    item_qty
item_0001    3
item_0002    7
item_0003    20
item_0004    6

如何在 hiveQL 中编写查询。请提出建议。

【问题讨论】:

    标签: sql hadoop hive hiveql


    【解决方案1】:
    SELECT T.item_name,SUM(T.item_qty) AS item_qty
    FROM
    (
    SELECT item_name,item_qty
    FROM table1
    UNION ALL
    SELECT item_name,item_qty
    FROM table2
    ) T
    GROUP BY T.item_name;
    

    【讨论】:

      【解决方案2】:

      基于How do I join two tables together that are in different databases, in Hive?

      你应该这样做:
      选择 db1.table1.field1、db2.table2.field2
      FROM db1.table1 别名1
      INNER JOIN db2.table2 alias2 ON alias1.field1 = alias2.field2
      INNER JOIN alias2, db.table3

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-25
        • 1970-01-01
        • 1970-01-01
        • 2018-04-30
        • 2017-11-21
        • 1970-01-01
        相关资源
        最近更新 更多