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

后端 未结 2 1071
广开言路
广开言路 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"
    

提交回复
热议问题