如何在3个表上的3个选择语句的结果中插入Hive的新表中


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个查询结果组合在一起,然后将它们放入Hive中称为table4的第4个表(如3个不同的列)中?

以下可以工作

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
)

最新更新