You could try having a small table with your transaction types in the first column and -1.0 or +1.0 on the second column named mult. Be sure to use currency or decimal types. NOT FLOATING POINT.
SELECT sum(mult * amount)
FROM
yourTable as t1
, smallTable as t2
WHERE
t1.TransactionType = t2.TransactionType
AND ... whatever
I'm not saying this is most efficient way to do it, but it should work
Main Topics
Browse All Topics





by: ram2098Posted on 2004-08-11 at 11:32:34ID: 11776770
Not sure I understood your requirement...If you want to get the sum of amounts based on Transaction Types (for sepcific transaction types)..here is the query.
select trastype,sum(amount)
from table1
where transtype in ('type1','type2') -- If you want to group only a few trans types ..else ignore this where clause
group by transtype
Let me know if I misunderstood your query.
Thanks -- Ram