SQL how to increase or decrease one for a int column in one command

前端 未结 6 2061
长情又很酷
长情又很酷 2020-12-04 09:10

I have an Orders table which has a Quantity column. During check in or check out, we need to update that Quantity column by one. Is there a way to do this in one action or w

6条回答
  •  醉话见心
    2020-12-04 09:39

    UPDATE Orders Order
    SET Order.Quantity =  Order.Quantity - 1
    WHERE SomeCondition(Order)
    

    As far as I know there is no build-in support for INSERT-OR-UPDATE in SQL. I suggest to create a stored procedure or use a conditional query to achiev this. Here you can find a collection of solutions for different databases.

提交回复
热议问题