var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: multiple sum statements in same query
I want to do a query that sums up all the transactions < 0 and transactions > 0, in one query.
So basically I will have
select sum(amount1) as amount_won, sum(amount2) as amount_loss...
in the same query, so amonut_won will be positive, while amount_loss will be negative. Is there a way to do this ?
I am already able to do this by running the query twice (once for < 0 and another time for > 0). But this will produce 2 result sets, and this will be harder to manipulate.
Thanks in advance !
case when amount > 0 then amount else 0 end
) as positivesum
case when amount < 0 then amount else 0 end
) as negativesum
thanks a lot ! that worked great !
select sum1, sum2 from (select sum(amt) sum1 from X where amt >=0) T1, (select sum(amt) sum1 from X where amt < 0) T2;