oracle 查询及删除表中重复数据
create table test1(
id number,
name varchar2(20)
);
insert into test1 values(1,'jack');
insert into test1 values(2,'jack');
insert into test1 values(3,'peter');
insert into test1 values(4,'red');
insert into test1 values(5,'green');
insert into test1 values(6,'green');
一 查询表中重复数据
1. 使用exists
select a.* from test1 a where exists (
select name from
( select name ,count(*)
from test1
group by name
having count(*)>1
) b
where a.name = b.name
);
2 join on
select a. * from test1 a
join (
select name ,count(*) from test1
group by name
having count(*)>1
) b
on a.name = b.name;
3 in
select a.name from test1 a
where a.name in
(
select name from test1
group by name
having count(*)>1
);
4 使用rowid 查询得到重复记录里,第一条插入记录后面的记录
select * from test1 a where rowid != (select min(rowid) from test1 b where b.name = a.name);
5 使用rowid查询得到重复记录里,最后一条记录之前插入的记录
select a.* from test1 a where rowid !=(select max(rowid) from test1 b where a.name=b.name);
6 使用rowid 查询得到 不重复的记录和重复记录里最后插入的一条记录
select a.* from test1 a where rowid =(select max(rowid) from test1 b where a.name=b.name);
7 使用rowid 查询得到不重复的记录和重复记录里最先插入的记录
select * from test1 a where rowid = (select min(rowid) from test1 b where b.name = a.name);
删除 所有重复不保留任何一条
delete from test1 a where exists ( select name from (select name ,count(*) from test1 group by name having count(*)>1) b where a.name = b.name);
delete from test1 a where a.name in (select name from test1 group by name having count(*)>1);
删除重复记录里,第一条重复记录后面插入的记录
delete from test1 a where rowid !=(select min(rowid) from test1 b where b.name = a.name);
删除先前插入的重复记录,保留最后插入的重复记录
delete from test1 a where rowid !=(select max(rowid) from test1 b where a.name=b.name);
oracle 查询及删除表中重复数据的更多相关文章
- 查询和删除表中重复数据sql语句
1.查询表中重复数据.select * from peoplewhere peopleId in (select peopleId from people group by ...
- mysql 查询及 删除表中重复数据
CREATE TABLE `test` ( `id` INT(20) NOT NULL AUTO_INCREMENT, `name` VARCHAR(20) NULL DEFAULT NULL, `a ...
- ROWID面试题-删除表中重复数据(重复数据保留一个)
/* ROWID是行ID,通过它一定可以定位到r任意一行的数据记录 ROWID DNAME DEPTNO LOC ------------------ ------------------------ ...
- sqlite 删除表中重复数据(亲测可用)
例子:表名 Paper .通过字段PaperID查找重复数据. 1 --查询某表中重复的数据 select * from Paper group by PaperID having co ...
- sql记录去重(SQL查询或者删除表中重复记录)
.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select*from people where peopleIdin (select peopleIdfrom peopl ...
- MySQL 数据库删除表中重复数据
采集数据的时候,由于先期对页面结构的分析不完善,导致采漏了一部分数据.完善代码之后重新运行 Scrapy,又采集了一些重复的数据,搜了下删除重复数据的方法. N.B. 删除数据表的重复数据时,请先备份 ...
- Oracle通过ROWID删除表中重复记录
-- 1 通过ROWID删除T1表里重复的记录 SELECT ROWID,A,B--DELETE FROM T1WHERE ROWID IN ( SELECT RD FROM ( ...
- oracle查询、删除表中相同的数据
delete FROM tablename a WHERE rowid > ( SELECT min(rowid) FROM tablename b WHERE b.id = a.id and ...
- SQL Server中删除表中重复数据
方法一:利用游标,但要注意主字段或标识列 declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max beg ...
随机推荐
- C#验证身份证号码正确性
18位号码: private static bool CheckIDCard18(string Id) { ; ), , ) || '), out n) == false) { return fals ...
- MongoDB单表导出与导入
mongoexport -h -u dbAdmin -p L-$LpGQ=FJvSf*****([l --authenticationDatabase=project_core_db -d proje ...
- sqlServer sa用户登陆失败的解决办法
sqlserver sa用户登陆失败的解决办法 如下图以此模仿: 1.右键-属性 2.找到安全: 3.勾选如图: 4.sa用户密码重置: 5.服务重启:
- 「BZOJ 5188」「Usaco2018 Jan」MooTube
题目链接 luogu bzoj \(Describe\) 有一个\(n\)个节点的树,边有权值,定义两个节点之间的距离为两点之间的路径上的最小边权 给你\(Q\)个询问,问你与点\(v\)的距离大于等 ...
- java大数据批量处理实现方式
1. 各批量方式对比 Mybatis与JDBC批量插入MySQL数据库性能测试及解决方案 2. 原理解析 1)MySql PreparedStatement executeBatch过慢问题 3. 工 ...
- apache-jmeter-3.1的简单压力测试使用方法(下载和安装)
博客转载https://blog.csdn.net/lan_shu/article/details/55190127 压力测试工具LoadRunner是收费的,而且操作复杂.作为开发人员当然是用apa ...
- 【bzoj4811】[Ynoi2017]由乃的OJ 树链剖分/LCT+贪心
Description 给你一个有n个点的树,每个点的包括一个位运算opt和一个权值x,位运算有&,l,^三种,分别用1,2,3表示. 每次询问包含三个数x,y,z,初始选定一个数v.然后v依 ...
- lamp centos下一键安装
系统需求 系统支持:CentOS 6+/Debian 7+/Ubuntu 12+ 内存要求:≥ 512MB 硬盘要求:至少 5GB 以上的剩余空间 服务器必须配置好 软件源 和 可连接外网 必须具有系 ...
- 错误代码: 1142 REFERENCES command denied to user 'wuyong'@'localhost' for table 'orders'
错误代码: 1142 REFERENCES command denied to user 'wuyong'@'localhost' for table 'orders' 原因:在使用SQLyog操作数 ...
- mysql 创建表时注意事项
mysql 创建表时注意事项 mysql 想必大家都不会陌生吧 是我学习中第一个接触的的数据库 已学习就很快上手的 这是一个关系型数据库 不懂什么是关系型数据库 啊哈哈哈 现在知道啦 因 ...