el ninho
el ninho

Reputation: 4233

Custom sums in SQL Server query

I have query that gives back results like this:

Client1 Product1 $500
Client1 Product2 $900
Client1 Product3 $400
Client2 Product1 $600
Client2 Product2 $100

And I need it like this:

Client1 Product1 $500
Client1 Product2 $900
Client1 Product3 $400
Client1 SUM      $1800
Client2 Product1 $600
Client2 Product2 $100
Client2 SUM      $700

Is somethig like this possible? Thanks.

Upvotes: 2

Views: 64

Answers (1)

tawman
tawman

Reputation: 2498

You can use the WITH ROLLUP expression on your GROUP BY statement to achieve the desired results: Summarizing Data Using ROLLUP

Upvotes: 5

Related Questions