2016-12-15 41 views
0
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列)?如何将3个表中的3个select语句的结果插入到Hive中的新表中?

回答

0

继可以工作

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 
) 
相关问题