鍍金池/ 問答/數(shù)據(jù)庫/ sql嵌套語句報錯

sql嵌套語句報錯

數(shù)據(jù)庫用的是MySQL,想拼接一個SQL查詢語句,語句中問號的地方是參數(shù),但是自己在測試SQL語句的時候,把那3個參數(shù)寫死更新數(shù)據(jù)也沒起作用,正確的SQL應該怎么寫?

數(shù)據(jù)表的內(nèi)容如下:
圖片描述

SQL語句如下:

update t_account set balance=(
select balance-?
from t_account
where account=?)
where account=?;

報錯如下:
[SQL] update t_account set balance=(
select balance-200
from t_account
where account=12345)
where account = 12345;
[Err] 1093 - You can't specify target table 't_account' for update in FROM clause

回答
編輯回答
小曖昧

可以更簡單點

update t_account set balance=balance-?
where account=?;
2017年5月11日 06:17