需要做的:一张表里,电话是唯一的,可是有很多重复的记录,现在要做的是 有重复记录的数据,电话号码 全部置为null
重复记录为:843条。
写了很多测试的如下:
1.
update club_member a, (select mobile from club_member group by mobile having count(*) >1) b
set a.mobile='' where a.mobile = b.mobile;
结果:失败,报错:You can't specify target table ‘’
错误提示就是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)
查了下百度和谷歌,说是Mysql的bug,有朋友建议等待mysql升级,哈哈。
2.
update club_member c set mobile=''
where exists (select 1 from club_member a where a.mobile is not null
group by a.mobile having count(*) >1)
结果:失败,同样的错误
3.
update club_member a, (select mobile from club_member group by mobile having count(*) >1) b
set a.mobile='' where a.mobile = b.mobile;
结果:成功,但是效率超低,重复记录843条,执行了将近5分钟
4.
update club_member c set mobile=''
where exists (select 1 from (select mobile from club_member a where a.mobile is not null
group by a.mobile having count(*) >1) b where b.mobile= c.mobile);
结果:成功,执行时间:9.91s
分析:
1、
<code>
select mobile from club_member a where a.mobile is not null
group by a.mobile having count(*) >1) b
</code>
最里层的子查询,查询出重复记录
2、
<code>
update club_member c set mobile=''
where exists (select 1 from (select mobile from club_member a where a.mobile is not null
group by a.mobile having count(*) >1) b where b.mobile= c.mobile);
</code>
where b.mobile=c.mobile 是与要修改的自关联表做比较相等
update club_member c set mobile='' 置为null
最后execute ok
oracle好像可以直接执行1。
Mark here!
分享到:
相关推荐
MySQL Error Code 详细说明
解决MySQL error code 145 Table was marked as crashed and should be repaired的方法
Error Code: 2006 - MySQL server has gone away 最终找到原因,原来是MySQL导入大批量数据的时候超出了默认允许最大的数据包所以就提示2006 – MySQL server has gone away 于是找到my.cnf,在[mysqld]加入: max...
...
。。。
项目中遇到的问题很奇怪,在Centos上安装了Mysql数据库,项目使用的是Spring Boot。 项目在本地启动连接服务器数据库正常、本地数据库客户端连接服务器数据库正常、服务器本地连接client连接数据库正常。唯独把项目...
error 日志当中的记录: [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist 从发了帖子,只有人看,没有人回复,看到这种情况只能自己解决问题了,自己动手...
本篇文章是对mysql数据库还原错误:(mysql Error Code: 1005 errno 121)的解决方法进行了详细的分析介绍,需要的朋友参考下
数据源连接池Durid连接Mycat+MySQL过程中报1243错误的解决办法。
本文给大家分享的是在使用mysql主从复制的时候遇到Error_code: 1872错误的解决方法,非常的简单,有需要的小伙伴可以参考下
mysql数据库常见错误代码既解决方法的小结,常见几种错误,问题解决小技巧。仅供参考。 mysql数据库常见错误代码既解决方法的小结,常见几种错误,问题解决小技巧。仅供参考。
mysql登录时出现了错误:ERROR 1045: Access denied for user,究竟是什么原因呢?接下来为你详细介绍下,感兴趣的你可以参考下哈,或许可以帮助到你
I meet with the error while calling stored procedures from the MySql in my Mac system server. It similar as the description below
代码如下:ERROR 1577 (HY000): Cannot proceed because system tables used by Event Scheduler were found damaged at server start。 查看手册(5.4. mysql_fix_privilege_tables:升级MySQL系统表),一些MySQL...
主要介绍了mysql登录报错提示:ERROR 1045 (28000)的解决方法,详细分析了出现MySQL登陆错误的原因与对应的解决方法,需要的朋友可以参考下
1.Mysql 数据库从本地导出、服务器上导入时报:ERROR 2005 (HY000): Unknown MySQL server host 'mysql' 的一种解决方案 2. mysql 出现 Error Code:1418 错误的解决办法 .......
Mysql报ERROR: ERROR 1615 (HY000): Prepared statement needs to be re-prepared 经过测试,发现不是合服脚本的问题。经过一番搜索。发现原来是mysql的变量值设置不合理引起的,调整以下值: table_open_cache 64=...
Mysql 错误代码集 0101 属于其他进程的专用标志。 0102 标志已经设置,无法关闭。 0103 无法再次设置该标志。 0104 中断时无法请求专用标志。 0105 此标志先前的所有权已终止。 。。。。。