饿虎岗资源网 Design By www.oxmxm.com
1、第一种重复很容易解决,不同数据库环境下方法相似:
以下为引用的内容:
Mysql
create table tmp select distinct * from tableName;
drop table tableName;
create table tableName select * from tmp;
drop table tmp;
SQL Server
select distinct * into #Tmp from tableName;
drop table tableName;
select * into tableName from #Tmp;
drop table #Tmp;
Oracle
create table tmp as select distinct * from tableName;
drop table tableName;
create table tableName as select * from tmp;
drop table tmp;
发生这种重复的原因是由于表设计不周而产生的,增加唯一索引列就可以解决此问题。
2、此类重复问题通常要求保留重复记录中的第一条记录,操作方法如下。 假设有重复的字段为Name,Address,要求得到这两个字段唯一的结果集
Mysql
以下为引用的内容:
alter table tableName add autoID int auto_increment not null;
create table tmp select min(autoID) as autoID from tableName group by Name,Address;
create table tmp2 select tableName.* from tableName,tmp where tableName.autoID = tmp.autoID;
drop table tableName;
rename table tmp2 to tableName;
SQL Server
select identity(int,1,1) as autoID, * into #Tmp from tableName;
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,Address;
drop table tableName;
select * into tableName from #Tmp where autoID in(select autoID from #Tmp2);
drop table #Tmp;
drop table #Tmp2;
Oracle
DELETE FROM tableName t1 WHERE t1.ROWID > (SELECT MIN(t2.ROWID) FROM tableName t2 WHERE t2.Name = t1.Name and t2.Address = t1.Address);
说明:
1. MySQL和SQL Server中最后一个select得到了Name,Address不重复的结果集(多了一个autoID字段,在大家实际写时可以写在select子句中省去此列)
2. 因为MySQL和SQL Server没有提供rowid机制,所以需要通过一个autoID列来实现行的唯一性,而利用Oracle的rowid处理就方便多了。而且使用ROWID是最高效的删除重复记录方法。
以下为引用的内容:
Mysql
create table tmp select distinct * from tableName;
drop table tableName;
create table tableName select * from tmp;
drop table tmp;
SQL Server
select distinct * into #Tmp from tableName;
drop table tableName;
select * into tableName from #Tmp;
drop table #Tmp;
Oracle
create table tmp as select distinct * from tableName;
drop table tableName;
create table tableName as select * from tmp;
drop table tmp;
发生这种重复的原因是由于表设计不周而产生的,增加唯一索引列就可以解决此问题。
2、此类重复问题通常要求保留重复记录中的第一条记录,操作方法如下。 假设有重复的字段为Name,Address,要求得到这两个字段唯一的结果集
Mysql
以下为引用的内容:
alter table tableName add autoID int auto_increment not null;
create table tmp select min(autoID) as autoID from tableName group by Name,Address;
create table tmp2 select tableName.* from tableName,tmp where tableName.autoID = tmp.autoID;
drop table tableName;
rename table tmp2 to tableName;
SQL Server
select identity(int,1,1) as autoID, * into #Tmp from tableName;
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,Address;
drop table tableName;
select * into tableName from #Tmp where autoID in(select autoID from #Tmp2);
drop table #Tmp;
drop table #Tmp2;
Oracle
DELETE FROM tableName t1 WHERE t1.ROWID > (SELECT MIN(t2.ROWID) FROM tableName t2 WHERE t2.Name = t1.Name and t2.Address = t1.Address);
说明:
1. MySQL和SQL Server中最后一个select得到了Name,Address不重复的结果集(多了一个autoID字段,在大家实际写时可以写在select子句中省去此列)
2. 因为MySQL和SQL Server没有提供rowid机制,所以需要通过一个autoID列来实现行的唯一性,而利用Oracle的rowid处理就方便多了。而且使用ROWID是最高效的删除重复记录方法。
饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com
暂无评论...
更新日志
2024年05月03日
2024年05月03日
- 群星《音你而来 第2期》[FLAC/分轨][197.58MB]
- 群星-中国新民乐(笛子)-戏竹4CD(DSD)[雨林唱片]WAV+CUE
- JacobCollier《DjesseVol.2》(2019)Hi-Res96kHz_24bit
- 黄品源.2002-漫漫岁月情·珍藏集(引进版)【滚石】【WAV+CUE】
- NorahJones《NotTooLate》(2024)Hi-Res192kHz_24bit
- RIMZEE《FeedTheStreets》(2024)[FLAC]
- 杭天琪.1989-入梦(TP版)【中唱】【WAV+CUE】
- 彭正《十年》[320K/MP3][98.75MB]
- 彭正《十年》[FLAC/分轨][288.77MB]
- 群星《惜花芷 影视原声带》[320K/MP3][128.04MB]
- 群星《经典老歌.百万畅销》10CD[WAV+CUE]
- 王韫.1994-漫天雪花飘的都是我的爱(TP版)【新时代】【WAV+CUE】
- HI-FI顶级人声测试天碟《试音刀郎DXD》[WAV+CUE]
- 群星《惜花芷 影视原声带》[FLAC/分轨][281.23MB]
- 张国荣《风继续吹》[DSF][1.1G]