SQL arithmetic for pairs of specific categories / values

I have a table with two columns. The items in the first column represent one of four categories, and the items in the second column represent the data referenced by their copy of the category:

CategoryA : 2
CategoryC : 1
CategoryB : 4
CategoryB : -1
CategoryD : 2
CategoryC : 1

and etc.

I need to build a SQL query that will return Sum for each of these categories, e.g.

CategoryA : 2
CategoryB : 3
CategoryC : 2
CategoryD : 2
+3
source share
2 answers

You can do this by combining the corresponding lines and adding up the values ​​for each:

select col1, sum(col2)
  from table_name
group by col1
+1
source
SELECT column1, SUM(column2) FROM table GROUP BY column1
0
source

All Articles