how to find the balance

oracle India
  • 13 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

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

    SELECT SUM(


            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).

Contribute

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.

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann