Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2016
    Posts
    1

    Unanswered: Calculate balance from Credit and Debit records

    I have the following records in my database table:

    Date Credit Debit Description
    --------------- ------- ------- ---------------
    12-24-2015 5 Purchased credit
    12-20-2015 1 Consumed credit
    12-15-2015 3 Purchased credit
    12-08-2015 1 Consumed credit
    12-08-2015 1 Consumed credit
    12-07-2015 1 Consumed credit
    12-04-2015 1 Consumed credit
    12-03-2015 1 Consumed credit
    12-01-2015 5 Purchased credit

    I want to calculate and display the balance for each record as shown below:

    Date Credit Debit Balance Description
    --------------- ------- ------- ------- -------------------
    12-24-2015 5 7 Purchased credit
    12-20-2015 1 2 Consumed credit
    12-15-2015 3 3 Purchased credit
    12-08-2015 1 0 Consumed credit
    12-08-2015 1 1 Consumed credit
    12-07-2015 1 2 Consumed credit
    12-04-2015 1 3 Consumed credit
    12-03-2015 1 4 Consumed credit
    12-01-2015 5 5 Purchased credit
    Can anyone please help me to achieve this result?

  2. #2
    Join Date
    Jun 2004
    Posts
    796
    Provided Answers: 1
    How do you get the second column of digits?
    90% of users' problems can be resolved by punching them - the other 10% by switching off their PCs.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    select date,credit,balance,credit-debit balance,decode(sign(credit-debit),1,'Purchased credit','Consumed credit') des
    from my_table
    order by date;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •