select * from table_name where xxx>0 and xxx!=2 order by VIEW_COUNT desc这条语句把所有的排序结果都返回了但我只想要最前边的10条,怎么做啊???row<=0是返回随机的最欠扁10条   不是排序后的啊。

解决方案 »

  1.   

    select * 
    from 
    (SELECT ROW_NUMBER() OVER(PARTITION BY VIEW_COUNT desc) RN,T.* FROM tb)
    where RN<=10;
      

  2.   

    select * from (select * from table_name where xxx>0 and xxx!=2 order by VIEW_COUNT desc 
    ) where rownum < 11 就可以了
      

  3.   

    我经过测试了,以下可以。
    select *
    from
    (SELECT ROW_NUMBER() OVER( order by VIEW_COUNT desc) RN,T.* FROM table_name t where xxx>0 and xxx!=2 )
    where RN <=10; 
      

  4.   

    select * from
      select T.*,rownum row_num from table_name T where xxx>0 and xxx!=2 order by VIEW_COUNT desc
    where row_num<=10; 试试
      

  5.   

    并不是随机的10条,而是rownum这个伪字段,是先为你的各个记录编上序号,你再按照order by子句的顺序排列,
    这是选择的前十条记录已经不是你排序后的记录。