Reputation: 568
I have the following table:
column1 | column2 | column3
1 3 4
5 7 6
how do I sum the values of say, column 2 and 3, to return the sum?
The expected result is:
res
7
13
Upvotes: 0
Views: 162
Reputation: 321
This works in postgresql.
select sum(col2+col3) from (
select col1, col2,col3,row_number() over() as rows from column_sum ) as foo
group by rows order by rows;
Upvotes: 1
Reputation: 6058
You can do maths within a select statement, so the following will work:
SELECT column2 + column3 AS res FROM table
Upvotes: 3