How to increase value by a certain number?

How to increase a value in a table by a certain number without reading last value and afterwards updating it?

product quantity
iLamp 50

I want to increase (or decrease) quantity by x. I am first reading last value (50), increasing or decreasing it, and writing it back. Is there a direct way?

70074 次浏览

Example 1 (for all rows):

UPDATE product SET price = price + 50

示例2 (针对特定行) :

UPDATE product SET price = price + 50 WHERE id = 1

示例3 (针对特定行) :

UPDATE product SET price = price + 50 WHERE id IN [1, 2, 3]

Example 4 (generic):

UPDATE {table} SET {column} = {column} + {value} WHERE {condition}

地点:

  • {table}-表名
  • {column}-列名
  • {value}-列的值应该增加或减少的数字
  • {condition}-一些条件,如果有的话