1. 首页
  2. IT资讯

记录一下避免排序和删除重复行

select distinct  owner, table_name from test_sort2 order by owner,table_name;

建立一个所以再OWNER ,TABLE_NAME
这样可以避免排序

select owner, table_name
  from test_sort2 a
 where A.ROWID = (select /*+ no_unnest */ max(rowid)
                    from test_sort2 b
                   where a.owner = b.owner
                     and a.table_name = b.table_name)
order by owner,table_name;

删除重复的行
SQL> select * from oo;
 
                                     IT
—————————————
                                      1
                                      1
                                      2
                                      2
 
SQL>
SQL> delete oo a where a.rowid <> (select  max(rowid)
  2                      from oo b
  3                     where a.it = b.it);
 
2 rows deleted
 
SQL> commit;
 
Commit complete
 
SQL> select * from oo;
 
                                     IT
—————————————
                                      1
                                      2

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7728585/viewspace-745223/,如需转载,请注明出处,否则将追究法律责任。

主题测试文章,只做测试使用。发布者:深沉的少年,转转请注明出处:http://www.cxybcw.com/183290.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code