用minus,用15条的结果集“减”5条的结果集。对于DB之查询一遍,“减法”的动作是在临时表空间里作的,不需要考虑效率。
GOOD LUCKY!

解决方案 »

  1.   

    select * from (select rownum rm,a.* from table a where rownum<10) where rm>=5
      

  2.   

    select * from (select rownum rn,a.* from table_name a where rownum<=10) where rn>=5;
      

  3.   

    谢谢各位大侠,不过这样的sql,会不会影响效率呢?
      

  4.   

       Declare 
         v_loopcounter Binary_Integer:=0;
         v1 varchar2(10);
         v2 varchar2(10);
         cousor totalmessage is 
           select  field1,field2  from tablename;
       Begin 
          open totalmessage;
          loop 
           fetch totalmessage into v1,v2;
           if (v_loopcounter>=5 ) and (v_loopcounter<=10)  then 
           dbms_output.put_line(v1||''||v2);          
           v_loopcounter:=v_loopcounter+1;
           exit when v_loopcounter>10;
          end loop
       End
      

  5.   

    SQLServer、MySql可以用select * from tablename limit 5,10
    --------------------------------------------------------
    mysql可以,但是sqlserver不可以。sqlserver:
    select identity(int,1,1) #id1,* into new from tablename;
    select * from new where id1 between 5 and 15;
    drop table #id1;
      

  6.   

    sorrey!
    sqlserver:
    select identity(int,1,1) id1,* into #new from tablename;
    select * from new where id1 between 5 and 15;
    drop table #new;
      

  7.   

    select * from tablename where rownum<=10
    minus
    select * from tablename where rownum<5
      

  8.   

    select * from (select rownum rm,a.* from table a where rownum<10) where rm>=5
    这已经是最高效的方式了,
      

  9.   

    楼上的是最好的了,用Minus的方式会自动过滤相同的记录,可能会出问题的
      

  10.   

    谢谢大家了,我平时用的都是下面的做法
    select * from tablename
    ...
    //跳到第5条
    for(int i=0;i<5;i++)
    {
       result.next();
    }
    //取10条记录
    int k=0;
    while(result.next()&&k<10)
    {
        //output result
        k++;
    }这种做法的效率高,还是这句
    select * from (select rownum rm,a.* from table a where rownum<10) where rm>=5
    的效率高呢?
    呵呵,不仅仅为了面试,平时也要注意修炼啊!
      

  11.   

    这样的话你相当于先把所有数据都去出来,
    然后相当于用游标fetch到相应的行上面
    对于数据量大的表或查询的话,这样效率肯定不高。