select rownum,no from person where rownum<8 order by no
minus
select rownum,no from person where rownum<0 order by no
该语句怎么写?为何第一句后面不能加order by ?

解决方案 »

  1.   

    为何第一句后面不能加order by ?
    :因为目前还不支持这种语法.
      

  2.   

    select * from (
    select rownum,no from person where rownum<8 
    minus
    select rownum,no from person where rownum<0 
    ) order by no;像这样写吧
      

  3.   

    rownum 是当符合条件记录集合生成的时候打上的一个序号标记所以序号标记先有然后才是 排序
      

  4.   


    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    连接到: 
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    SQL> select rownum,id from test where rownum <8 order by id;    ROWNUM         ID
    ---------- ----------
             1          1
             2          2
             3          3
             4          4
             5          5
             6          6
             7          7已选择7行。SQL> select rownum,id from test where rownum < 8 
      2  minus
      3  select rownum,id from test where rownum < 0 order by id;    ROWNUM         ID
    ---------- ----------
             1          1
             2          2
             3          3
             4          4
             5          5
             6          6
             7          7已选择7行。
    其中ID是主键 
      

  5.   

    SQL> ed
    已写入文件 afiedt.buf  1  select rownum,id from test where rownum < 8
      2  minus
      3* select rownum,id from test where rownum < 0 order by id
    SQL> /    ROWNUM         ID
    ---------- ----------
             1          1
             2          2
             3          3
             4          4
             5          5
             6          6
             7          7已选择7行。