今天做題的時候,發現一個很鬱悶的地方,經過問人搜索之後,找到了答案。
題目 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 );