SQL - Updating each row with a grouped by total
Let's pretend you have an SQL table like this:
and you want to fill in the column with the total for each person based on the Donation column
You can use the following SQL command:
| Name | Donation | Total Amount |
| Alice | 10 | |
| Alice | 12 | |
| Alice | 8 | |
| Alice | 9 | |
| Bob | 2 | |
| Bob | 3 |
UPDATE table SET "Total Amount" = x.total from ( SELECT "Name", SUM("Amount") AS total FROM table GROUP BY Name ) AS x WHERE x.Name = Name;