MySQL通过子查询更新

18-12-06 09:36 字数 289 阅读 3120

一般情况下可能会直接上来这么写

update sqd_a set amount = amount * 0.1 where id in (select id from sqd_b where is_dividend = 1 and get_time < 1);

但是会直接报错 [1093] You can't specify target table 'sqd_a' for update in FROM clause

正确的写法是这样的

update sqd_a as  a,(select id from sqd_b where is_dividend = 1 and get_time < 1) as b set a.amount = a.amount * 0.1 where a.id = b.id;
1人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
191
收藏
31
排名 : 1
访问 : 130.19万
私信