我有两个表格与
相同的表格table1/table2 comprises of columns item_name and item_qty, sample data looks like
表1中的示例数据
item_name item_qty
item_0001 3
item_0002 7
item_0003 5
item_0004 4
表2中的示例数据
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中编写查询。请建议。
答案 0 :(得分:3)
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;
答案 1 :(得分:1)
基于How do I join two tables together that are in different databases, in Hive?
你应该这样做:
SELECT db1.table1.field1,db2.table2.field2
FROM db1.table1 alias1
INNER JOIN db2.table2 alias2 ON alias1.field1 = alias2.field2
INNER JOIN alias2,db.table3