新手学数据库编程,遇到索引问题,描述如下:A表结构
a,b,c,d,e
B表结构m,n,x,y,z表特点记录数略大,必须建索引A表a是关键字,B表m是关键字,A,B已经建立了关键字索引现在要执行这样的查询语法,来得到结果集中的从指定位置处开始的20条记录
select a,b,c,x,y from A,B where A.c=B.z and a.rowid not in(select a.rowid from A,B where A.c=B.z and rownum<12345600) and rownum<=20 order by A.b
如果不进行索引,就10000条记录查询,用20分钟,现在的问题是,对于这样的查询要求,如何建立索引......在线等,分不够开贴另给

解决方案 »

  1.   

    select * from (select a,b,c,x,y from A,B where A.c=B.z and rownum <=12345620)
    minus
    select * from (select a,b,c,x,y from A,B where A.c=B.z and rownum <=12345600)
      

  2.   

    Select * from ( Select a,b,c,x,y from A,B where A.c=B.z 
     minus
     Select a,b,c,x,y from A,B where A.c=B.z and rownum<12345600
     ) t Where rownum<=20
      

  3.   

    not in的效率是非常低的,好像要遍历所有数据.
      

  4.   

    rownum<=20 order by A.b这样写是得不到按A.b排序的前20条记录的,oracle取前20条必须用
    select * from (select ... order by a.b) where rownum<=20