F
Frank Sung
Hi,
How to write a SQL query to get account's monthly balances?
A table looks like below.
Account Date Trans. Int. Rate
======= ======== ======== ========
0001 01/01/04 $100 3%
0001 02/01/04 $0 2%
0001 03/01/04 $50 1%
0001 04/01/04 -$100 2%
0001 05/01/04 $0 1%
0002 01/01/04 $200 3%
0002 02/01/04 -$50 2%
0002 03/01/04 $0 1%
0002 04/01/04 $50 2%
0002 05/01/04 $0 1%
The query's result should look like below.
Account Date Beg Bal Trans. End Balance
======= ======== ======== ======== ========
0001 01/01/04 $0.00 $100.00 $103.00 =(0+100)*(1+3%)
0001 02/01/04 $103.00 $0.00 $105.06 =(103+0)*(1+2%)
0001 03/01/04 $105.06 $50.00 $156.61 =(105.06+50)*(1+1%)
0001 04/01/04 $156.61 -$100.00 $57.74 =(156.61-100)*(1+2%)
0001 05/01/04 $57.74 $0.00 $58.32 =(57.74+0)*(1+1%)
0002 01/01/04 $0.00 $200.00 $206.00 =(0+200)*(1+3%)
0002 02/01/04 $206.00 -$50.00 $159.12 =(206-50)*(1+2%)
0002 03/01/04 $159.12 $0.00 $160.71 =(159.12+0)*(1+1%)
0002 04/01/04 $160.71 $50.00 $214.92 =(160.71+50)*(1+2%)
0002 05/01/04 $214.92 $0.00 $217.07 =(214.92+0)*(1+1%)
Beginning balance is last month's ending balance.
Ending balance = (Beginning balance + Transaction) * (1 + Interest Rate)
Thank you in advance.
Frank
How to write a SQL query to get account's monthly balances?
A table looks like below.
Account Date Trans. Int. Rate
======= ======== ======== ========
0001 01/01/04 $100 3%
0001 02/01/04 $0 2%
0001 03/01/04 $50 1%
0001 04/01/04 -$100 2%
0001 05/01/04 $0 1%
0002 01/01/04 $200 3%
0002 02/01/04 -$50 2%
0002 03/01/04 $0 1%
0002 04/01/04 $50 2%
0002 05/01/04 $0 1%
The query's result should look like below.
Account Date Beg Bal Trans. End Balance
======= ======== ======== ======== ========
0001 01/01/04 $0.00 $100.00 $103.00 =(0+100)*(1+3%)
0001 02/01/04 $103.00 $0.00 $105.06 =(103+0)*(1+2%)
0001 03/01/04 $105.06 $50.00 $156.61 =(105.06+50)*(1+1%)
0001 04/01/04 $156.61 -$100.00 $57.74 =(156.61-100)*(1+2%)
0001 05/01/04 $57.74 $0.00 $58.32 =(57.74+0)*(1+1%)
0002 01/01/04 $0.00 $200.00 $206.00 =(0+200)*(1+3%)
0002 02/01/04 $206.00 -$50.00 $159.12 =(206-50)*(1+2%)
0002 03/01/04 $159.12 $0.00 $160.71 =(159.12+0)*(1+1%)
0002 04/01/04 $160.71 $50.00 $214.92 =(160.71+50)*(1+2%)
0002 05/01/04 $214.92 $0.00 $217.07 =(214.92+0)*(1+1%)
Beginning balance is last month's ending balance.
Ending balance = (Beginning balance + Transaction) * (1 + Interest Rate)
Thank you in advance.
Frank