Suppose I have a table like this:
id col1 col2 col3
1 a 1 k1
2 a 2 k2
3 a -3 k3
4 b 3 k4
Now, I want the total of column ‘col2’ for all rows where ‘col1’ is the same as ‘col1’ in the row where ‘id’ = 1.
So that would be 1+2-3=0.
How would I express this in SQL?
1 Answer