2016-12-15 43 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 
) 
相關問題