热线电话:13121318867

登录
2019-02-14 阅读量: 810
sql嵌套语句报错

问题描述:

数据库用的是MySQL,想拼接一个SQL查询语句,语句中问号的地方是参数,但是自己在测试SQL语句的时候,把那3个参数写死更新数据也没起作用,正确的SQL应该怎么写?

数据表的内容如下:

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=?;
0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子