假设select a,b from c where b=1 order by a有10条结果,我想不通过循环直接取到第5条,能不能做到?语句应该怎么写??

解决方案 »

  1.   

    select a,b from (select rownum as no,a,b from (select a,b from c where b=1 order by a) t1) t2 where no=5;
      

  2.   

    select a,b from (select rownum as no,a,b from c where b=1 order by a) t1 where no=5;
      

  3.   

    wiler(@_@) ( ) 信誉:100    Blog  2006-12-02 13:15:13  得分: 0  
     
     
       select a,b from (select rownum as no,a,b from c where b=1 order by a) t1 where no=5;
      
     
    ------------
    你这样是错误的,select会先得到rownum然后再order by
      

  4.   

    SQL> drop table tab_t;Table droppedSQL> create table tab_t(
      2  a number(2),
      3  b number(1)
      4  );Table createdSQL> insert into tab_t values(1,1);1 row insertedSQL> insert into tab_t values(5,1);1 row insertedSQL> insert into tab_t values(9,1);1 row insertedSQL> insert into tab_t values(10,1);1 row insertedSQL> insert into tab_t values(8,1);1 row insertedSQL> insert into tab_t values(20,1);1 row insertedSQL> commit;Commit completeSQL> select a,b from (select rownum as no,a,b from tab_t where b=1 order by a) t1 where no=5;  A  B
    --- --
      8  1SQL> select a,b from (select rownum as no,a,b from (select a,b from tab_t where b=1 order by a) t1) t2 where no=5;  A  B
    --- --
     10  1经过验证,NinGoo(宁哥 http://NinGoo.itpub.net)是对的,谢谢NinGoo(宁哥 http://NinGoo.itpub.net)
      

  5.   

    呵呵,两个都是高手,平时得到wiler(@_@) 的帮助比较多,进来学习一下:)