need help to solve the query of finding balances
533216Sep 12 2006 — edited Sep 12 2006hi,
This is my query.
Transaction Table
Amount Debit Ac Credit A/C
6000 101 34
2000 29 101
3000 102 29
1000 101 39
1000 45 101
5000 34 102
1000 22 101
As u can see accountid 101 has 2 entries as debitAc.
So the debit sum is 7000. Similarly it has 3 entries
as credit A/c summing up 4000. So the balance is
7000-4000=3000 for accountid 101. I want this balance.
I tried like this.
select sum(amount) from transaction where debitac=101;
select sum(amount) from transaction where creditac=101;
then got the subtracted value as balance.
Here I have to find balances for accountids like
101,102,etc.
For all such available accountids i made a while loop
to find the sum as debitac and creditac and then
balance(by subtracting) for each accountid.
I dont want to use queries inside while loop. I may be
in need of finding balances for 8 to 10 such
accountids 101, 102, ..., 108 (not necessary in
sequence order) for a single web page.
so I want this in a single query.
Pls reply as soon as possible.