How to update a field based on its current value in MySQL?

后端 未结 2 1069
广开言路
广开言路 2021-02-19 02:54

Is it possible to get the current value of a field, use it as a variable in a calculation, then update the field based on the result?

For example the record with the ID

相关标签:
2条回答
  • 2021-02-19 03:06

    This will set the result column to the value of the CurrentID column (plus 1) of the same row, for any row that has an ID column that equals "1":

    UPDATE table1
    SET result = CurrentID + 1
    WHERE ID = "1"
    
    0 讨论(0)
  • 2021-02-19 03:30

    You might try

    Update table1 set ID = ID+1 where ID = 1
    
    0 讨论(0)
提交回复
热议问题