Mysql中不能update自身的解决方法

不能执行:
update bi_data.order_all_detail
set err_msg='同时存在于wx,zfb平台',proc_time=now()
where order_no in
(
select order_no
from bi_data.order_all_detail
group by order_no
having count(distinct platform)>1
)

提示:1093 - You can't specify target table 'order_all_detail' for update in FROM clause
######

解决:再加一层子查询:
update bi_data.order_all_detail
set err_msg='同时存在于wx,zfb平台',proc_time=now()
where order_no in
(
select order_no
from (
select order_no
from bi_data.order_all_detail
group by order_no
having count(distinct platform)>1
) tt
)

posted @ 2021-12-01 11:20  xiaoyongdata  阅读(279)  评论(0编辑  收藏  举报