0

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.

enter image description here.

3
  • What are you trying to do here? Are you trying to write a query to extract information, or do you really want to update the table you described? Commented Mar 28, 2017 at 6:03
  • I am just looking for a way to sum the amount of multiple reciever column ,update the amount and remove (delete) the other columns Commented Mar 28, 2017 at 6:05
  • 1
    Other columns? Do you mean other rows? Please include your expected output from the above sample input. Commented Mar 28, 2017 at 6:06

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this

SELECT receiver, SUM(amount) as total FROM table GROUP BY receiver 

This will add all amount with the same receiver

2 Comments

yes, I just want update the amount and live one row for each receiver
@ssshehu You're asking for a fairly complex operation, but are you sure you need it? I think it would be easier to just write the data to a new table and delete the old one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.