今天做题的时候,发现一个很郁闷的地方,经过问人搜索之后,找到了答案。
题目 https://blog.csdn.net/weixin_42845682/article/details/105449417
是因为:mysql 不能对同一个表进行 update(delete) 和 select 联合操作
例如:
update a set a.x = 1 where a.y in (select a.x from a);
上边语法是错误的,在对update 时不能再条件中对同一个a表进行 select 操作
如果非得要操作 那只能 把 条件中 再关联一次(不能的缘由是因为 条件中的查询是 在 临时表中查的,保存却是原表,解决方法就是将查询和保存都放在临时就可以了)
写成这样就可以了:
update a set a.x = 1 where a.y in ( select t.x from (select x from a)t );