Transferring and summing values from an SQL column

Asked

Viewed 101 times

2

I have two columns in a table, I need the values in column 1 to be transferred and added to the values in column 2.

This can be done with a PHP or is there some easier way to do it?

Original:
ID /  1  /  2  /
1    150   100
2    200   50
3    75    175

Como deve ficar:
ID /  1  /  2  /
1     0    250
2     0    250
3     0    250

1 answer

5


There is not much secret to do this in SQL. You didn’t give a lot of details about the table but basically this is to do in all rows:

UPDATE tabela SET col2 = col1 + col2, col1 = 0;

I put in the Github for future reference.

This is adding up the two columns and playing the result on the second, as you say you want.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.