Skip to content
Advertisement

SQL Add total sum row for each property

I’m trying to create a new total sum row for every state.

Sample table:

Result:

Is there SQL query that I can use to execute that table

Advertisement

Answer

In SQL Server you can use ROLLUP on a GROUP BY clause to get intermediate and overall sums over the grouped by fields. In your case you would group by both state and item to get all rows:

Output:

Demo on SQLFiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement