-1

I have a table SalesDetails with the following schema:

CustomerID TotalDue ShippingAdress
1          100      aaa
1          200      aaa
1          300      bbb
2          100      ccc
2          400      ddd
2          700      ccc         

And I I need a query that will surmise the above table into a new table with the following schema:

CustomerID SumDue ShippingAdress
1          300      aaa
1          300      bbb
2          800      ccc
2          400      ddd

Currently I am using a 'Group By' on the CustomerID and SUM 'TotalDue'. But I do not know how to conditionally sum the TotalDue based on both CustomerID and ShippingAddress.

Any help would be much appreciated.

3

1 Answer 1

1

You are looking for a simple GROUP BY:

select CustomerId, sum(TotalDue) as sumDue, ShippingAdress
from t
group by CustomerId, ShippingAdress
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.