alex
alex

Reputation: 51

SUM SQL Function For Columns

I have a sql query that is outputting:

col1    col2
A        1
B        3
C        4
D        5

Is there a way to add a column where it outputs the sum of all the numbers in col2?

col1    col2  col3
A        1     13
B        3     13
C        4     13
D        5     13

Upvotes: 0

Views: 90

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269503

You can use window functions:

select col1, col2, sum(col2) over () as col3
from t;

Upvotes: 1

Related Questions