写一下修改库存的 SQL 语句
假设有一个商品库存表名为 product_inventory
,包含字段 product_id
(商品 ID)、quantity
(库存数量)。
以下是一个简单的 SQL 语句示例,用于减少库存(假设购买一件商品):
UPDATE product_inventory
SET quantity = quantity - 1
WHERE product_id = <具体商品 ID>;
如果要增加库存,可以使用以下语句:
UPDATE product_inventory
SET quantity = quantity + <增加的数量>
WHERE product_id = <具体商品 ID>;
在实际应用中,可能需要考虑更多的情况,比如库存不能为负数,可以添加条件判断:
UPDATE product_inventory
SET quantity = CASE WHEN quantity - 1 >= 0 THEN