我有这个简单的查询来更新产品数量:
$updprqty='UPDATE products set
available_qty = available_qty - '.$qty.'
WHERE id = '.$pid.'';
我还应该添加什么,以便获得available_qty的新值? 感谢
答案 0 :(得分:1)
您也可以查看此链接,您可能会对此有更多的了解
答案 1 :(得分:0)
$updprqty='UPDATE products set
available_qty = (select available_qty from products where id = ' .$pid . ') - '.$qty.'
WHERE id = '.$pid.'';
介绍别名
$updprqty='update products set available_qty = x.available_qty from (select available_qty, id from products) - '.$qty.' where id = ' .$pid . ') as x where id = x.id';