当前位置:网站首页>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)
边栏推荐
- 2021年12月电子学会图形化一级编程题解析含答案:下雨
- 6000 字+,帮你搞懂互联网架构演变历程!
- 请问下,flink cdc监控oracle,我看源码是通过sid方式的,请问怎么改成service
- 不安装运行时运行.NET程序
- Ruoyi Ruoyi framework @DataScope annotation use and some problems encountered
- 袁小林:沃尔沃专注于出行的安全感,并且把它做到极致
- DC-DC 2C (40W/30W) JD6606SX2 power back application
- Three key expectations for the crypto market in August Price moves north?Still expected to be in turmoil
- Flink作业调度详解
- 扩展欧几里得求逆元实例
猜你喜欢
随机推荐
使用虚幻引擎自动化工具实现自动化部署
js数组方法总结
unity用代码生成LightProbeGroup
ffplay视频播放原理分析
cnpm 安装成功后提示不是内部和外部命令,也不是可运行的命令解决方案
2021年12月电子学会图形化二级编程题解析含答案:绘制多边形
身为售后工程师的我还是觉得软件测试香,转行成功定薪11.5K,特来分享下经验。
使用Make/CMake编译ARM裸机程序(基于HT32F52352 Cortex-M0+)
在 360 度绩效评估中应该问的 20 个问题
方舟开服教程win
0 code 4 steps to experience IoT devices on the cloud
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
全新探险者以40万的产品击穿豪华SUV价格壁垒
如何选择合适的损失函数,请看......
【周报】2022年7月31日
Fortinet产品导入AWS AMI操作文档
AI+BI+可视化,Sugar BI架构深度剖析
Deep Learning - Install CUDA and CUDNN to implement GPU operation of tensorflow
How to use binary search and find whether the rotation in the array contains a (target) value?Rotate the sorted array leetcode 81. Search
深入浅出Flask PIN









