我有一个列transfer_quantity
,其初始值为0.当我在输入字段输入一些数字时
<input type="number" name="qtyBuy">
我想将transfer_quantity
更新为qtyBuy
值。
这是我的初始代码:
UPDATE stock_transfer SET stocks_transferred = $qtyBuy WHERE transfer_product_id = 1 ON DUPLICATE KEY UPDATE stocks_transferred = stocks_transferred + $qtyBuy;
以下是一个例子:
|stocks_transferred|
| 0 |
当我输入10时,这应该是结果:
|stocks_transferred|
| 10 |
如果我输入25,则应在
中添加10|stocks_transferred|
| 35 |
我该怎么做?
答案 0 :(得分:1)
UPDATE stock_transfer SET stocks_transferred = stocks_transferred + $qtyBuy WHERE transfer_product_id = 1