Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57962
  • 博文数量: 13
  • 博客积分: 318
  • 博客等级: 二等列兵
  • 技术积分: 185
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-01 19:17
文章分类

全部博文(13)

文章存档

2012年(13)

我的朋友

分类: Oracle

2012-04-26 22:47:22

--查询表中的重复记录
--方法一
select c.*
  from dchngrouprolegrant c
 where exists (select 1
          from (select max(a.rowid) as row_id, a.group_id
                  from dchngrouprolegrant a
                 where exists (select 1
                          from dchngrouprolegrant b
                         where a.rowid <> b.rowid
                           and a.group_id = b.group_id)
                 group by a.group_id) t
         where c.group_id = t.group_id
           and c.rowid <> t.row_id);
--方法二
declare
begin
  for rec in (select a.group_id as group_id, count(a.group_id) as cn
                from dchngrouprolegrant a
               group by a.group_id
              having count(a.group_id) > 1) loop
    delete from dchngrouprolegrant a
     where a.group_id = rec.group_id
       and rownum < rec.cn;
    commit;
  end loop;
  commit;
end;
--方法三--分析函数
select a.rowid, a.*
  from dChnToCUser a
 where a.rowid in (select rid
                     from (select rowid rid,
                                  row_number() over(partition by subs_id order by rn asc) rn
                             from dChnToCUser)
                    where rn <> 1)
--方法四--伪列自关联
select a.rowid, a.*
  from dChnToCUser a
 where a.rowid <
       (select max(rowid) from dChnToCUser where subs_id = a.subs_id);
阅读(1664) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~