SQL Query that retains previous balance
741191Apr 9 2010 — edited Apr 12 2010Hello all,
First time Oracle forms user here.
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 64-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
I want to create a running balance similar to a bank statement such that a beginning balance is calculated then
as records are read, either the debit amount or the credit amount is added initially to the beginning balance
then from that resulting calculation the next record's debit or credit is added to show the next value.
There are separate 'Where' conditions for gathering the beginng balance, the credits and the debits
The difficulty I am having is retaining the calculated balance from one record to the next.
The input is from several tables joined together so it is difficult to show sample data. I can provide the SQL I have tried so far if needed.
The output should look like this:
EmpCode Credit Debit Balance
EC100 null null $1000.00
null null $500.00 $1500.00
null null $100.00 $1600.00
null $50.00 null $1550.00
null $100.00 null $1450.00
Emp. Totals $1450.00
Any help is appreciated.