2019-02-14
閱讀量:
883
sql嵌套語句報(bào)錯(cuò)
問題描述:
數(shù)據(jù)庫用的是MySQL,想拼接一個(gè)SQL查詢語句,語句中問號(hào)的地方是參數(shù),但是自己在測試SQL語句的時(shí)候,把那3個(gè)參數(shù)寫死更新數(shù)據(jù)也沒起作用,正確的SQL應(yīng)該怎么寫?
數(shù)據(jù)表的內(nèi)容如下:

SQL語句如下:
update t_account set balance=(
select balance-?
from t_account
where account=?)
where account=?;
報(bào)錯(cuò)如下:
[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=?;






評(píng)論(0)


暫無數(shù)據(jù)
CDA考試動(dòng)態(tài)
CDA報(bào)考指南
推薦帖子
0條評(píng)論
0條評(píng)論
0條評(píng)論
0條評(píng)論