Transfer and sum values from an SQL column

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.

Can this 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
    
asked by anonymous 06.08.2015 / 23:29

1 answer

5

There is not much secret to doing this in SQL. You did not give too many details about the table but basically this is to do on all lines:

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

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

    
06.08.2015 / 23:32