DB2如何从两个不同的表中对两列进行求和

时间:2014-12-31 07:14:58

标签: sql db2 sum

Select sum(amt) as totalA from tableA where id>10;
Select sum(amount) as totalB from tableB where people = 'JOSH';

如果目标是sum(totalA + totalB)

,最好的方法是什么?

1 个答案:

答案 0 :(得分:2)

select sum(total) from
(
    select sum(amt) as total from tableA where id>10
    union all
    select sum(amount) from tableB where people = 'JOSH'
) as q