我有三个表(t1,t2,t3)的并集。每个重新运行的记录数完全相同,第一列是id,第二个量是:
1 10 2 20 3 20 1 30 2 30 3 10 1 20 2 40 3 50
是否有一种 简单 的sql方式将其总结为:
1 60 2 80 3 80
select id, sum(amount) from ( select id,amount from table_1 union all select id,amount from table_2 union all select id,amount from table_3 ) x group by id