SuicideSheep
SuicideSheep

Reputation: 5550

DB2 how to sum two column from two different table

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

What is the best way if the objective is to have sum(totalA + totalB)?

Upvotes: 0

Views: 1870

Answers (1)

Iłya Bursov
Iłya Bursov

Reputation: 24146

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

Upvotes: 2

Related Questions