How to minus a number in the same table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hungnguyenjn
    New Member
    • Mar 2008
    • 1

    How to minus a number in the same table

    I am write a asp.net application, I want to make a report by connect to access database to take out the result. but I don't know how to do. In addition, My English is just a little so I can not describe my idea. please, forgive me, if you don't understand what I describe. :(
    My access data have a table such as below:
    product Quantity status date/time
    P0001 1 In
    P0002 3 out
    P0003 1 in
    P0004 2 in
    P0005 4 out
    P0006 3 in
    P0006 3 out
    P0003 3 in
    P0001 1 In

    I want to calculate the quantity of these products after in and out but I don't know how to find out. I want the result like below:
    product quantity
    P0001 2
    P0002 -3
    P0003 4
    P0004 2
    P0005 -4
    P0006 0
    Please, help me!
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    I am guessing you are asking for the query you need to write in access.

    So something like this
    [code=sql]
    SELECT Product,sum(iif (status="IN",Qu antity,Quantity *-1)) as Qty
    FROM YourTable
    GROUP BY Product
    [/code]

    Comment

    Working...