Mysql sum column value and update other filed with total

50
January 13, 2019, at 03:50 AM

I have the following table..

Id  Amount Balance total
1     10     15     A
2     10     12     A
3      4     11     A
4     10      6     A

What I need, calculate the total and update the value in the same table (Replace A). This is the result I want...

Id  Amount Balance total
1     10     15     25
2     10     12     22
3      4     11     15
4     10      6     16

How do I achieve that in mysql query?

Answer 1

update table set total = Amount + Balance;

READ ALSO
INNER JOIN with Condition - Mysql

INNER JOIN with Condition - Mysql

I'm trying to make an inner join if a condition is true but it does not work, I've tried these 2 ways:

29
How do I preserve a UTF8 character set when doing an update into MySQL, from a Google Sheet?

How do I preserve a UTF8 character set when doing an update into MySQL, from a Google Sheet?

I have an app to upload a spreadsheet into my MySQL databaseSome of the fields contain Unicode characters from Northwest Indian languages

45
In C Language, store MySQL row data as variable to avoid segmentation fault with RPi/GPIO stuffs

In C Language, store MySQL row data as variable to avoid segmentation fault with RPi/GPIO stuffs

This is most-likely a stupid beginners questionFor starters, here's my C code [segment]:

44
How to update FK linked to multiple table - Cascade on Update

How to update FK linked to multiple table - Cascade on Update

I have 3 tables which are linked to each other

57