大成小鱼 2021-10-26 10:08 采纳率: 100%
浏览 30
已结题

mysql中delete删除数据,为何如下第一种写法报错,但是第二种就可以了呢?

1、删除表中的数据,第一次写如下:

[SQL]delete  from yizhu_zhixing_plan_expire 
where plan_id in (
select t.plan_id from yizhu_zhixing_plan_expire  t
 where  yizhu_plan_date>=date_format(now() ,'%Y-%m-%d')
and EXISTS (select 1 from yizhu_basic_info a where a.zuhao_id=t.zuhao_id and a.yizhu_State='开始执行' -- and a.type='长期' 
    )
)

[Err] 1093 - You can't specify target table 'yizhu_zhixing_plan_expire' for update in FROM clause  



报错如上:
2、修改脚本后,执行成功了


[SQL]delete  from yizhu_zhixing_plan_expire 
where plan_id in (
select m.plan_id from (
select t.*from yizhu_zhixing_plan_expire  t
 where  yizhu_plan_date>=date_format(now() ,'%Y-%m-%d')
and EXISTS (select 1 from yizhu_basic_info a where a.zuhao_id=t.zuhao_id and a.yizhu_State='开始执行'  
    ) ) m
)

受影响的行: 0
时间: 2.008s

这个是为啥呢?求指导1

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 系统已结题 11月3日
  • 已采纳回答 10月26日
  • 创建了问题 10月26日

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计