union all里不能用order by。
sql="select * from (select * from pc_spe_info where rownum<=5 union all select * from pc_spe_info where rownum<=10) order by num"

解决方案 »

  1.   

    select ROWNUM,COLUMN_NAME from pc_spe_info where rownum<=5 union all
    select ROWNUM,COLUMN_NAME from pc_spe_info where rownum<=10 order by 1;
    (1 IS ROWNUM)
      

  2.   

    select * from 
    (select * from pc_spe_info where rownum<=5 union all select * from pc_spe_info where rownum<=10) order by num
      

  3.   

    sorry上面的回答有问题(并不是在union all中不能order by):
    只要把要order by的列名写在select中就没有问题了。
    SQL> select rownum,id from test2 union all select rownum,id from test2 order by
    id;    ROWNUM         ID
    ---------- ----------
             3          1
             3          1
             2          4
             2          4
             4          6
             5          6
             4          6
             5          6
             1         62
             1         6210 rows selected.SQL> select rownum num,id from test2 union all select rownum num,id from test2 o
    rder by num;       NUM         ID
    ---------- ----------
             1         62
             1         62
             2          4
             2          4
             3          1
             3          1
             4          6
             4          6
             5          6
             5          610 rows selected.
      

  4.   

    语句原本想表达的意思是
    (select * from pc_spe_info where rownum<=5 )union all (select * from pc_spe_info where rownum<=10 order by num)不知该如何写?
      

  5.   

    你的num是rownum还是表里的其他的字段呀?
      

  6.   

    ok了,这样:
    (select * from pc_spe_info where rownum<=5 )union all (select * from (select * from pc_spe_info where rownum<=10 order by num);
      

  7.   

    少了个右括号
    (select * from pc_spe_info where rownum<=5 )union all (select * from (select * from pc_spe_info where rownum<=10 order by num));
      

  8.   

    又出现错误:
    ADODB.Recordset 错误 '800a0e78' 
    对象关闭时,不允许操作。 
    /ynnw/computer/index.asp,行338 行338为:while not rs.EOF 
    怎么回事?