James Cheng
James Cheng

Reputation: 1

Trying to figure out the sum of a certain variable not total sum using sql

I'm having a mindblank here but my question is quick.

I have a table like the following:

Cust    Part    Qty    Rtn Qty 
Joe      A1      2        0 
Joe      A2      3        1 
Joe      A1      2        2
Bob      A1      3        4
Bob      A2      4        0

I want the results to be like:

Joe      A1      4        2
Joe      A2      3        1
Bob      A1      3        0
Bob      A2      4        0

I'm trying to figure out how to create a sum for each customer individually according to the part?

Upvotes: 0

Views: 52

Answers (1)

Andomar
Andomar

Reputation: 238196

That looks like a straightforward group by on Cust, Part:

select  Cust
,       Part
,       sum(Qty)
,       sum([Rtn Qty])
from    YourTable
group by
        Cust
,       Part

Upvotes: 2

Related Questions