martinenzinger
martinenzinger

Reputation: 2286

SQL: select distinct on column1 and sum up column2 values of merged rows

How could one achieve to get sums of column values regarding tags in a second column?

tag1  1000
tag1  2000
tag2  1000
tag3  1000
tag2  3000
tag1  1000
tag3  1000
tag3  1000
tag2  2000
tag3  2000

The required result looks like this

tag1  4000
tag2  6000
tag3  5000

Upvotes: 1

Views: 306

Answers (1)

radar
radar

Reputation: 13425

GROUP BY on the tag column with sum

SELECT tagColumn, sum(tagValue) as TotalCount
FROM Table1
GROUP BY tagColumn

Upvotes: 1

Related Questions