簡體   English   中英

MySQL查詢更新行並返回相同查詢的新值

[英]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的新值? 謝謝

您也可以檢查此鏈接,也許您會對此有所了解

在MySQL中獲取更新的值,而不是受影響的行

$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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM