I have this select:
"Select * from table" that return:
Id | Value |
---|---|
1 | 1 |
1 | 1 |
2 | 10 |
2 | 10 |
My goal is create a sum from each Value group by id like this:
Id | Value | Sum |
---|---|---|
1 | 1 | 2 |
1 | 1 | 2 |
2 | 10 | 20 |
2 | 10 | 20 |
I Have tried ways like:
SELECT Id,Value, (SELECT SUM(Value) FROM Table V2 WHERE V2.Id= V.Id GROUP BY IDRNC ) FROM Table v;
But the is not grouping by id.
Id | Value | Sum |
---|---|---|
1 | 1 | 1 |
1 | 1 | 1 |
2 | 10 | 10 |
2 | 10 | 10 |
Aggregation aggregates rows, reducing the number of records in the output. In this case you want to apply the result of a computation to each of your records, task carried out by the corresponding window function.
Check the demo here.