How to add a value to the current one in each of the rows of a mysql table?

2

I have the following table in a mysql database:

Iwouldlikeacommandtoruninphpmyadmin,addthecurrentvalueoftherating_sumcolumnto5,andrating_countto1,thus:

I want to add these values (5, 1) to all table rows, without any restrictions. I tried some things I found here in the OS, but they were examples to display the total value of a given column, and it's not what I need.

How could I do it?

    
asked by anonymous 16.06.2017 / 04:49

1 answer

2

When you want to do a sum (among other operations) update of a column on all rows in a table, you just reference the column itself in update without setting where (this will cause all rows in table are updated). In each line the value that is already filled in the fields will be used.

In your case, something like this:

UPDATE BANCO.TABELA SET rating_sum = ( rating_sum + 5 ), rating_count = ( rating_count + 1 );

    
16.06.2017 / 05:18