Is it possible to add summary in rows with group by: To be specific i am looking for the below output.
Main Table
Client|Billing
--------------
a | 34
a | 27
b | 29
b | 27
c | 28
c | 37
Output should look alike:
Client|Billing
--------------
a | 34
a | 27
Total | 61
b | 29
b | 27
Total | 56
c | 28
c | 37
Total | 65
Here the first total is the sum of billing for client a, similarly the next 2 totals are the sum of client b and c respectively.
i am able to achieve similar kind of requirement with the below code: select cast(Client as varchar(10)) Client, Billing from mydata union all select 'Total', sum(Billing) from mydata group by Client
however the total rows are coming at the end, like below :(
Client|Billing
a |34
a |27
b |29
b |27
c |28
c |37
Total |61
Total |56
Total |65