您的位置:首页 > 数据库 > Oracle

oracle查询重复数据并删除掉多余部分

2017-01-02 10:39 323 查看
--查询重复的数据:

select t.stu_name, t.class_name, t.score

  from tb3 t

 where exists (select t1.stu_name

          from tb3 t1

         where t1.stu_name = t.stu_name

         group by t1.stu_name

        having count(t1.stu_name) > 1);

--删除重复数据

delete from tb3 t

 where rowid > (select min(rowid)

                  from tb3 t1

                 where t1.stu_name = t.stu_name

                 group by t1.stu_name

                having count(t1.stu_name) > 1);

commit;

--还有一种方法:

delete from tb2 t

 where t.stu_name in (select stu_name

                        from tb2

                       group by stu_name

                      having count(stu_name) > 1)

   and rowid not in (select min(rowid)

                       from tb2

                      group by stu_name

                     having
4000
count(stu_name) > 1);

commit;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle 数据