Reputation: 881
I have a data like this:
col1 value
A 2
B 4
C 8
D 6
I want to calculate the ratios to the column total
col1 value
A 10%
B 20%
C 40%
D 30%
How can I do this with SQL?
Upvotes: 0
Views: 182
Reputation: 1269583
You can use window functions:
select t.*, value * 100.0 / sum(value) over () as perentage
from t;
Upvotes: 1