我需要从两个不同的表计数中向hive表中插入数据。
示例,假设我有一个表sample
,其中有字段counter1
和counter2
现在我还有另外两个表test1
和test2
。
我需要插入sample.counter1 as select count(*) from test1
和sample.counter2 as select count(*) from test2
如果最终表具有一列,例如:
insert into table sample select count(*) from test1
现在我需要插入两列。
有什么建议吗?
答案 0 :(得分:1)
这是您要寻找的吗?
insert into sample.counter1 (counter1, counter2)
select t1.cnt, t2.cnt
from (select count(*) as cnt from test1) t1 cross join
(select count(*) as cnt from test2) t2;