Phil Phil - 6 months ago 27
SQL Question

Switch SQL result columns to rows and include a summary row beneath

I'd like the below columns to populate in the place of rows and then include a summary row beneath it:

ID NAME Value Group
001 Bob 100 A
002 Don 200 A
003 Fay 300 B

Below is an example of the desired output:

Group A 2 300
Group B 1 300
Total 3 600

Answer Source
select coalesce('Group '+ [group], 'Total') [Group], count([group]) No, sum(value) SUM
from table1
group by [group] with rollup!6/655f4/3

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download