MySQL通过子查询更新

saonian 发布于 18-12-06 09:36 836 点击
一般情况下可能会直接上来这么写 ```mysql 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** 正确的写法是这样的 ```mysql 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; ```
0 评论

请登录后发表评论

saonian

all or nothing, now or never.

文章
回复
粉丝