![](/img/trans.png)
[英]How Can I Query for Unique Value and Update another Field in Same Table If return True mysql php
[英]Mysql query to update row and return the new value with the same query
我有这个简单的查询,可以更新产品数量:
$updprqty='UPDATE products set
available_qty = available_qty - '.$qty.'
WHERE id = '.$pid.'';
我还应该添加什么,以便获得available_qty的新值? 谢谢
您也可以检查此链接,也许您会对此有所了解
$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';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.