当前位置:网站首页>mysql delete 执行报错:You can‘t specify target table ‘doctor_info‘ for update in FROM clause
mysql delete 执行报错:You can‘t specify target table ‘doctor_info‘ for update in FROM clause
2022-08-03 15:48:00 【心心念念的小鼠标】
因为一些测试原因,导致医生表里出现了两个医生ID相同的数据,也就是所谓的脏数据,那么如何把多余的那条删除掉呢?
一、首先筛选出条数大于1条的:
select doctor_id,count(doctor_id) from `doctor_info` where `scale_group_id`="31" group by doctor_id having count(doctor_id)>1
二、决定删除其中的那一条?max/min
1、max
select max(id) as id from doctor_group_permission where `scale_group_id`="24120868141551631" group by doctor_id having count(doctor_id)>1
2、min
select min(id) as id from doctor_group_permission where `scale_group_id`="24120868141551631" group by doctor_id having count(doctor_id)>1
三、数据筛选出来了,直接delete 报错了
delete from doctor_info where id in(select max(id) as id from doctor_info where `scale_group_id`="31" group by doctor_id having count(doctor_id)>1)
四、错误说明
不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值。
借用临时表来处理一下,前端时间写过一个update的,链接在此
五、正确delete操作 借用临时表a
delete from doctor_info where id in(select a.id from(select max(id) as id from doctor_info where `scale_group_id`="31" group by doctor_id having count(doctor_id)>1) a)
边栏推荐
- Windows服务器如何防止黑客入侵的安全设置
- Ruoyi Ruoyi framework @DataScope annotation use and some problems encountered
- 泰山OFFICE技术讲座:段落边框的绘制难点在哪里?
- How to use binary search and find whether the rotation in the array contains a (target) value?Rotate the sorted array leetcode 81. Search
- 30W 2C(JD6606S + FP6652X2)BOM
- After the cnpm installation is successful, the prompt is not an internal and external command, nor is it a runnable command solution
- AWS中国区SDN Connector
- 您的移动端app安全吗
- 如何选择合适的损失函数,请看......
- [微信小程序开发者工具] × #initialize
猜你喜欢

【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例

NodeJs - cross domain

2021年12月电子学会图形化四级编程题解析含答案:新冠疫苗接种系统
![leetcode: 899. Ordered Queue [Thinking Question]](/img/e0/5ea1df0d40a166d0be0309b4608e6d.png)
leetcode: 899. Ordered Queue [Thinking Question]

2021年12月电子学会图形化二级编程题解析含答案:绘制多边形

ffplay视频播放原理分析

After the cnpm installation is successful, the prompt is not an internal and external command, nor is it a runnable command solution

Awesome!Coroutines are finally here!Thread is about to be in the past

使用Make/CMake编译ARM裸机程序(基于HT32F52352 Cortex-M0+)

ECCV 2022 | 基于关系查询的时序动作检测方法
随机推荐
After the cnpm installation is successful, the prompt is not an internal and external command, nor is it a runnable command solution
JS基础--判断
无内鬼,来点干货!SQL优化和诊断
美国国防部更“青睐”光量子系统研究路线
MATLAB gcf figure save image with black background/transparent background
web漏洞之远程命令/代码执行
基于牛顿方法在直流微电网潮流研究(Matlab代码实现)
深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行
JS basics--judgment
DC-DC 2C(40W/30W) JD6606SX2退功率应用
高可用版 主数据库数据结构改变 备数据库会自动改变吗
红蓝对抗经验分享:CS免杀姿势
AI+BI+可视化,Sugar BI架构深度剖析
Essentially a database data recovery 】 【 database cannot read data recovery case
leetcode:899. 有序队列【思维题】
方舟开服教程win
人脸识别损失函数的汇总 | Pytorch版本实现
FATFS | 中文显示 | 长文件名
cmd 关闭端口
【码蹄集新手村600题】将一个函数定义宏