How do I write this query?

From: Bliss <bliss_is_ignorance_at_hotmail.com>
Date: Tue, 17 Jun 2003 09:57:25 +0800
Message-ID: <3eee74f5_2_at_news.tm.net.my>


Hi all,

I have a table accounts having the following columns

Ac_Date   - Transaction Date date type
Ac_Debit  - Debit Amount number(5)
Ac_Credit - Credit Amount number(5)

Records in this table will be something like this
Ac_Date         Ac_Debit    Ac_Credit
01-Jun-2003    10000           5000
02-Jun-2003      2000           1500
05-Jun-2003    20000         15000
07-Jun-2003    30000                 0
08-Jun-2003            0            1000

I want 2 outputs showing me the balance
1st format

Date                  Debit          Credit      Balance (Debit - Credit)
01-Jun-2003    10000           6000         4000 (10000-6000)
02-Jun-2003      2000           1500           500 (2000-1500)
05-Jun-2003    20000         15000         5000 (20000-15000)
07-Jun-2003    30000                 0       30000 (30000-0)
08-Jun-2003            0            1000      -1000  (0-1000)

2nd format
Date                  Debit          Credit      Balance
01-Jun-2003    10000           6000         4000 (10000-6000)
02-Jun-2003      2000           1500         4500 (4000 i.e. previous
balance + 2000-1500)
05-Jun-2003    20000         15000         9500 (4500+20000-15000)
07-Jun-2003    30000                 0       39500 (9500+30000-0)
08-Jun-2003            0            1000      38500 (39500+0-1000)

How do I write an SQL Query to arrive at the above 2nd format?

Thanks in advance
Bliss Received on Tue Jun 17 2003 - 03:57:25 CEST

Original text of this message