当前位置:网站首页>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)
边栏推荐
- How to prevent hacking Windows server security Settings
- 2021年12月电子学会图形化二级编程题解析含答案:消灭蝙蝠
- 2021年12月电子学会图形化三级编程题解析含答案:数星星
- 技术干货|如何将 Pulsar 数据快速且无缝接入 Apache Doris
- 如何用二分法搜索、查找旋转数组中是否含有某个(目标)值? leetcode 81.搜索旋转排序数组
- 2021年12月电子学会图形化一级编程题解析含答案:下雨
- MySQL性能优化_小表驱动大表
- 深入浅出Flask PIN
- How to use binary search and find whether the rotation in the array contains a (target) value?Rotate the sorted array leetcode 81. Search
- How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
猜你喜欢

并发编程的核心问题

Three key expectations for the crypto market in August Price moves north?Still expected to be in turmoil

JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商

Ark server opening tutorial win

动态链接库.dll、.so和静态库.a,cmake指令

CS免杀姿势

【899. Ordered Queue】

How to get the 2 d space prior to ViT?UMA & Hong Kong institute of technology & ali SP - ViT, study for visual Transformer 2 d space prior knowledge!.

土耳其国防部:联合协调中心将对首艘乌克兰粮船进行安全检查

深入浅出Flask PIN
随机推荐
C#.NET 国密数字信封
动态链接库.dll、.so和静态库.a,cmake指令
MySQL性能优化_小表驱动大表
分享一款免费OPC UA服务器
扫雷?拿来吧你(递归展开+坐标标记)
ruoyi若依框架@DataScope注解使用以及碰到的一些问题
MATLAB gcf figure save image with black background/transparent background
深入浅出Flask PIN
unity用代码生成LightProbeGroup
人脸识别损失函数的汇总 | Pytorch版本实现
30W 2C(JD6606S + FP6652X2)BOM
上亿数据怎么玩深度分页?兼容MySQL + ES + MongoDB
Convex Optimization of Optimal Power Flow (OPF) in Microgrids and DC Grids (Matlab Code Implementation)
基于DMS的数仓智能运维服务,知多少?
微电网和直流电网中最优潮流(OPF)的凸优化(Matlab代码实现)
【网络结构】VGG
使用Make/CMake编译ARM裸机程序(基于HT32F52352 Cortex-M0+)
冒烟测试冒烟测试
【码蹄集新手村600题】将一个函数定义宏
js数组方法总结