Skip to content
Advertisement

SQL – return each column and it’s sum as rows

I have a table like this:

I need a select which will return something like:

Basically I need the field’s name and it’s sum. Is it possible with a sql query?

PS: If it’s not possible to get the field’s name and it’s sum dynamically, I can type them 1 by 1 (they’re about 20).

Advertisement

Answer

you need to unpivot the data and do the aggregation

Here is an ANSI SQL method

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