Reputation: 9
I am having a difficulty in summing and updating those row amount to one row of the same receiving column.
please can someone help me. here is the image.
Upvotes: 0
Views: 37
Reputation: 520968
If I understand your requirement, you want to delete all records from the original table, leaving only one per receiver
. And you want to update the amount
for that remaining record to the sum of amounts for all records, for that receiver
. Rather than trying to deal with a complex update and delete operation, I might recommend that you just create a new table and insert the data you want into that:
CREATE TABLE new_table (receiver varchar(11), amount int);
INSERT INTO new_table (receiver, amount)
SELECT receiver, SUM(amount)
FROM original_table
GROUP BY receiver
Then, you can drop the original table since you don't need/want it anymore.
Upvotes: 1
Reputation: 5401
Try this
SELECT receiver, SUM(amount) as total
FROM table
GROUP BY receiver
This will add all amount
with the same receiver
Upvotes: 1