Good afternoon,
I have a MySQL table in which there are several duplicate rows that need to be removed by adding the value from one column in duplicated rows to the original.
The problem arose when the other column had the wrong values, and now it is fixed, but it left the scales divided between different lines that need to be added together. Then new lines that have been added should be deleted.
In this example, the userid column determines whether they are duplicate (or triple). userid 6 is duplicated, and user ID 3 is three times.
As an example for userid 3, he should add all the residues from rows 3, 11 and 13 and should put this number on row 3 and then delete rows 11 and 13. The balance columns of both of them should be added together to the original, bottom row of the identifier and new, higher identifier lines should be removed.
ID | balance | userid --------------------- 1 | 10 | 1 2 | 15 | 2 3 | 300 | 3 4 | 80 | 4 5 | 0 | 5 6 | 65 | 6 7 | 178 | 7 8 | 201 | 8 9 | 92 | 9 10 | 0 | 10 11 | 140 | 3 12 | 46 | 6 13 | 30 | 3
I hope this is clear enough and that I have provided enough information. Thanks =)
source share