有表t1(index_1, amount, stat_time)和t_2(index_2, amount, stat_time),
t_3(index_3, amount, stat_time),
index_1,index_2,index_3由序列产生,是表的主键,现
t_1有数据
index_1 amount stat_time
1 4 2008-7-9
2 5 2008-7-10t_2有数据
index_2 amount stat_time
3 5 2008-7-8
5 2 2008-7-9需得到t_3
index_3 amount stat_time
1 5 2008-7-8
2 6 2008-7-9
3 5 2008-7-10
t_3(index_3, amount, stat_time),
index_1,index_2,index_3由序列产生,是表的主键,现
t_1有数据
index_1 amount stat_time
1 4 2008-7-9
2 5 2008-7-10t_2有数据
index_2 amount stat_time
3 5 2008-7-8
5 2 2008-7-9需得到t_3
index_3 amount stat_time
1 5 2008-7-8
2 6 2008-7-9
3 5 2008-7-10
select 序列的.nextval, sum(amount) amount, stat_time
from (select *
from t_1
union all
select * from t_2) t
group by stat_time
order by stat_time
SELECT INDEX_3.NEXTVAL, SUM(AMOUNT) AMOUNT, STAT_TIME
FROM (SELECT *
FROM T_1
UNION ALL
SELECT * FROM T_2) T
GROUP BY STAT_TIME
ORDER BY STAT_TIME;
INSERT INTO t_3
SELECT seq_3.NEXTVAL, amount, stat_time
FROM (SELECT stat_time, SUM (amount) amount
FROM (SELECT amount stat_time
FROM t_1
UNION ALL
SELECT amount stat_time
FROM t_1)
GROUP BY stat_time
ORDER BY stat_time)