select rownum from (select l.* from users u left join log l on u.id=l.user_id where u.id = 1)t where rownum>0 and rownum<45;这样能查到44条数据,
 可是我把前面那个条件 rownum>0 随便改成>1的就一条数据都查不到了.晕哦.不知道在回事

解决方案 »

  1.   

    rownum从1开始,你查询 >1的,而rownum不能直接跳过1而到2,所以查询不到
      

  2.   

    select * from
    (
      select l.* , rownum cnt from users u left join log l on u.id=l.user_id where u.id = 1
    ) t
    where cnt > 1 and cnt < 45select * from
    (
      select l.* , rownum cnt from users u left join log l on u.id=l.user_id where u.id = 1
    ) t
    where cnt between 2 and 44
      

  3.   

    rownum是一个序列,只能包含rownum=1否则就查询不到 
      

  4.   

    rownum只能与<或者<=做比较
    不能用>或者>=
    如果要取1<rownum<45的话可以用 minus
    select rownum from (select l.* from users u left join log l on u.id=l.user_id where u.id = 1)t where rownum<45
    minus
    select rownum from (select l.* from users u left join log l on u.id=l.user_id where u.id = 1)t where rownum<1;
      

  5.   

    上面的解决方案都对,要么两层查询要么用minus做减法你对rownum这个伪列的理解不足阿,
    rownum是本次查询结构的序号从1开始,你规定rownum > 1,数数怎么能从2开始
    rownum > 0的条件也是没意义的,楼上说得很对rownum只能与<或者<=做比较另外,一定要避免rownum直接与order by连用,根据表的定义和数据,执行的先后顺序及结果是不确定的,
    遇到这种情况要用两层查询来做
      

  6.   

    select * from
    (
      select l.* , rownum cnt from users u left join log l on u.id=l.user_id where u.id = 1
    ) t
    where cnt > 1 and cnt < 45
      

  7.   

    rownum是一个伪劣!只能从1开始取,若有才取2,这样递增的!
      

  8.   

    你的rownum 要放在里面查询,命名一个别名,然后外面 对这个别名进行查询。
      

  9.   

    你这样能查到   直接使用 rownum>0 因为是从1开始的 1>0是true   特例 但是rownum 是从1开始的 要想像你的那样必须嵌套 傅别名
     select  t.* from (select l.*,rownum rn from users u left join log l on u.id=l.user_id where u.id = 1 and rownum<=45 )t where  rn<=44;
      

  10.   

    rownum是一个伪劣!只能从1开始取!要想取出来,必须先把rownum做为结果集中的列才能越过1.select * from
    (SELECT ROWNUM R,e.*  FROM (select l.* from users u left join log l on u.id=l.user_id where u.id = 1) e WHERE ROWNUM <= 1000) a where r>1
      

  11.   


    select * from
    (SELECT ROWNUM R,e.*  FROM (
    select l.* from users u left join log l on u.id=l.user_id where u.id = 1
    ) e WHERE ROWNUM <= 45) a where r>1
      

  12.   

    谢谢各位...我好像有点明白了.知道不能直接查询rownum的第2条记录.嘿嘿.