how to find the balance

oracle India
  • 14 years ago

    my table like shown below

    name            status             amount

    x               credit                  500

    y               credit                 400

    z              credit                    600

    x                 debit               300

    y                  debit            100

    z            debit                    400

    now i would like to fine the balace amount of each name

    like  x=amount

    y= amount

    z=    amount

    only sql query

  • 14 years ago
    I suppouse this should solve your problem:


            CASE WHEN status = 'debit' THEN amount * -1

    ELSE amount END) as amount FROM your_table
        GROUP BY name;

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An expert is a man who has made all the mistakes that can be made in a very narrow field” - Niels Bohr