如果想从表中取出按照某字段排序前M到N条记录
SQL> select ID from
     ( select ID , rownum as con from
       (   select ID  from TestSort order by ID
       )
       where rownum <= 3   /*N值*/
     )
     where con >= 2;  /*M 值*/ 

解决方案 »

  1.   

    select * from table
    where rownum <(select count(*)+1  from table )
    and rownum>(select count(*)-3  from table )
      

  2.   

    http://expert.csdn.net/Expert/topic/2566/2566792.xml?temp=.6758234
    很详细了!
      

  3.   

    如何在查询中选择从第m条记录开始的m条记录呢?
    select * from (select *,rownum from you_table where rownum<m+m+1) 
    where rownum>m-1 and rownum<m+m+1 
      

  4.   

    谢谢各位。
    但有个问题:
       为什么我的where后面的rownum>7不起作用?
       select * from t_mygod
       where rownum < (select count(*)+1  from t_mygod )
       and rownum>(select count(*)-3  from t_mygod )
       /
    结果为  未选定行
      为啥rownum<x 可以执行 而  rownum>x却不能执行?
       请指教
      

  5.   

    请教:
       select * from t_mygod 
       where rownum>3
       /
      未选定行 可我t_mygod里有10条记录。为什么呢?
      

  6.   

    select * from test where rownum < 5 order by id desc
      

  7.   

    rownum是根据你选择的记录集来判定的,显然是不能适用大于符号的,呵呵
      

  8.   

    select * from t_mygod 
       where rownum>3
    只能是<3,不能选大于号