The rating table has a record ID and a user ID. How can the duplicate user scores be collapsed by setting the value of rank equal to the sum of all his grades to write?
CREATE TABLE Rank ( `id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `postId` INT(11) NOT NULL, `userId` INT(11) NOT NULL, `rank` INT(11) NOT NULL, ); |------|--------|--------|------| | id | postId | userId | rank | |------|--------|--------|------| | 1 | 1 | 1 | 5 | | 2 | 1 | 2 | 5 | | 3 | 1 | 1 | 4 | | 4 | 2 | 2 | 5 | | 5 | 2 | 1 | 2 | | 6 | 3 | 1 | 3 | | 7 | 3 | 1 | 4 | |------|--------|--------|------| After transformation:
|------|--------|--------|------| | id | postId | userId | rank | |------|--------|--------|------| | 1 | 1 | 1 | 9 | | 2 | 1 | 2 | 5 | | 4 | 2 | 2 | 5 | | 5 | 2 | 1 | 2 | | 6 | 3 | 1 | 7 | |------|--------|--------|------|