现在有一个表,里面有若干重复行,现在我们对其做如下处理:

1.显示重复记录

2.显示非重复记录

3.显示所有记录,如有重复只显示一次

4.删除重复的记录,每个记录只保留一个

 SQL> select * from tt;

         X          Y
---------- ----------
         5          6
         5          6
         1          2
         1          3
         1          4
         1          2
         1          3
         1          3
         3          4
         3          5
         3          5

         X          Y
---------- ----------
         5          6

如上表

1.显示重复的记录

     方法一: select * from tt having count(*)>1 group by (x,y);

     方法二: select distinct * from tt where rowid not in (select max(rowid) from tt group by (x,y));

2.显示非重复的记录

     方法一:select * from tt having count(*)=1 group by (x,y);

     方法二:select * from tt minus(select * from tt having count(*)>1 group by (x,y));

3.显示所有记录,如有重复只显示一次

     方法一:select distinct * from tt;

     方法二:select * from tt where rowid in (select max(rowid) from tt group by (x,y));

4.删除重复记录,每个记录保留一次

     方法一:delete from tt where rowid not in
                            (select max(rowid) from tt group by (x,y));


--------------------------------------------------------------------------------

为啥找不到SQL的代码输入器,难看死了,就先这把,希望大家指点指点,另外,我的CSDN博客上有同样的文章,管理员就别费心了。