问题
I would like to perform an UPDATE
in MYSQL
in which I take a field value, add a constant and save the new value in the same field.
Let's assume that we have a column called OldValue
in a table called aTable
.
Pseudocode could be:
UPDATE aTable SET OldValue = OldValue + 220 WHERE someField = someValue
Do you have any idea on how I could do that? I would like to use a single query (on some administration panel) without making a php
script. (Of course, in that case the answer is quite simple.)
回答1:
Your code will work.
See it working in SQLFiddle.
I used your exact query verbatim, except for substituting a real value for "someValue".
回答2:
Here is a working example using Pseudocode from original question itself.
UPDATE `table1` SET `field1` = `field1` - 18, `field2` = `field2` + 16 WHERE n_id IN (111,222,333) OR form IN ('Digital Editing','Studio Room') AND location_id LIKE ('%home-page10%')
来源:https://stackoverflow.com/questions/14605924/update-a-table-field-to-its-value-plus-a-constant-on-mysql-w-o-php