I have a table:
ColA | ColB
1 1
2 1
2 1
3 1
4 1
5 1
I would like to sum ColB only once where ColA = 2.
Essentially, I would like to sum the values of ColB as if the table looked like
ColA | ColB
1 1
2 1
3 1
4 1
5 1
So the sum of ColB should be 5 not 6
Any ideas on how I can do this?
This site got me close, but it doesn't add either of the ColB values for the rows where ColA = 2.
A2
= 1,A3
= 2, andA4
also = 2, what do you want to have happen ifB3
≠B4
? (Or are all theB
values equal to 1? If so, you’re talking about a count rather than a sum.) Do you guarantee that theA
values are sorted?