-------------------------------------- credit_id | debit_id | Amount -------------------------------------- | 1 4 10 | | 1 3 10 | | 1 2 10 | | 2 1 20 | | 3 1 20 | | 5 1 20 | ----------------------------------------
select (select sum(Amount) from table3 where debit_id ='1') - (select sum(Amount) from table3 where credit_id ='1')
select (select sum(amount) from table3 where credit_id ='5') - (SELECT IF((select count(*) from table3 WHERE debit_id='5') > 0, (select sum(amount) from table3 where debit_id ='5'), 0))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)