ic3man7019
ic3man7019

Reputation: 711

How can I group a set of similar results and add up values for one final result in SQL?

I know there has to be a simple answer to this question, but I am a total SQL noob. In my result set I have multiple results in one column that have one specific value that is repeated several times. In another column there is another value that needs to be added. Please see the attached photo for clarification. enter image description here

I want to be able to find all of the values in Column B that correspond to 'A' and add them up for one result like shown. I want to be sure to delete the duplicates in Column A. Any help is greatly appreciated.

Upvotes: 0

Views: 37

Answers (1)

Tom H
Tom H

Reputation: 47444

You're trying to SUM the values in column B and you're trying to group them by (GROUP BY) the value in column A when you do that. This is accomplished like so:

SELECT
    col_a,
    SUM(col_b)
FROM
    My_Table
GROUP BY
    col_a

Upvotes: 4

Related Questions