欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle重复行查询实例教程

程序员文章站 2022-04-14 10:28:58
oracle重复行查询实例教程 create table dlp_test (a number(2),b number(2)); insert into dlp_test values(...

oracle重复行查询实例教程

create table dlp_test (a number(2),b number(2));

 insert into dlp_test values(1,2);
 insert into dlp_test values(1,2);
 insert into dlp_test values(3,4);
 insert into dlp_test values(5,6);
 insert into dlp_test values(3,5); 
 insert into dlp_test values(3,5);
select * from  dlp_test ;

Oracle重复行查询实例教程

--获取不重复行
select distinct x.* from dlp_test x;

--获取仅出现一次的行
--①
select a.*
  from dlp_test a,
       (select a, b from dlp_test group by a, b having count(*) = 1) b
 where a.a = b.a
   and a.b = b.b;
--②
select *
  from dlp_test
 where rowid in (select rowid
                   from (select a, b, count(*) over(partition by a, b) t
                           from dlp_test)
                  where t = 1);