Is there a way in PostgreSQL to take this table:
ID | country | name | values |
---|---|---|---|
1 | USA | John Smith | {1,2,3} |
2 | USA | Jane Smith | {0,1,3} |
3 | USA | Jane Doe | {1,1,1} |
4 | USA | John Doe | {0,2,4} |
and generate this table from it with the column agg_values
:
ID | country | name | values | agg_values |
---|---|---|---|---|
1 | USA | John Smith | {1,2,3} | {0,1,3,1,1,1,0,2,4} |
2 | USA | Jane Smith | {0,1,3} | {1,2,3,1,1,1,0,2,4} |
3 | USA | Jane Doe | {1,1,1} | {1,2,3,0,1,3,0,2,4} |
4 | USA | John Doe | {0,2,4} | {1,2,3,0,1,3,1,1,1} |
Where each row aggregates all values
except from the current row and its peers.
So if name = John Smith
then agg_values = aggregate of all values where name not = John Smith
. Is that possible?