如何将3个表上的3个select语句的结果插入到配置单元中的新表中?

jaxagkaj  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(325)
select sum(column_table1) from table1 where job_run_time_stamp >= '2016-12-15 00:00:00' and job_run_time_stamp < '2016-12-16 00:00:00';
select sum(column_table2) from table2 where job_run_time_stamp >= '2016-12-15 00:00:00' and job_run_time_stamp < '2016-12-16 00:00:00';
select sum(column_table3) from table3 where job_run_time_stamp >= '2016-12-15 00:00:00' and job_run_time_stamp < '2016-12-16 00:00:00';

如何组合上述3个查询结果并将它们放入名为 table4 在 hive 里?

h43kikqp

h43kikqp1#

以下方法可以奏效

insert into table4
values(
select sum(t.sum1) , sum(t.sum2), sum(t.sum3) from 
(select sum(column_table1) as sum1 , 0 as sum2, 0 as sum3 from table1 where     job_run_time_stamp >= '2016-12-15 00:00:00' and job_run_time_stamp < '2016-12-16 00:00:00'
union
select 0, sum(column_table2) , 0 from table2 where job_run_time_stamp >= '2016-12-15 00:00:00' and job_run_time_stamp < '2016-12-16 00:00:00' 
union
select 0,0, sum(column_table3) from table3 where job_run_time_stamp >= '2016-12-15 00:00:00' and job_run_time_stamp < '2016-12-16 00:00:00') as t
)

相关问题