Sum query two table

  • Hello guys, i have table in and out, how to query get result.

  • This should do the trick:

    Identify the columns you want to group by --> ID_Order, ID_Product from either table

    Identify the columns you want to aggregate --> IN.Amount, Out.Amount

    Identify the columns you need to join Table IN and Out --> ID_Order, here maybe you also need ID_Product depending on your data structure

    select In.ID_Order
    ,In.ID_Product
    ,IN_Sum=sum(IN.Amount)
    ,Out_Sum = sum(OUT.Amount)
    from Table_IN IN
    inner join Table_Out OUT on IN.ID_Order = Out.ID_Order
    group by IN.ID_Order
    ,IN.ID_Product

     

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply