O8i之前的版本不支持子查询中使用order by子句,所以一定要改成group by
select * 
  from (select * 
          from table a
         group by a.num, a.col1, a.col2...) 
 where rownum<6;

解决方案 »

  1.   

    那么.我想查最大的5个值该怎么写的?
    按照你的SQL.我好象只能取最小的值
      

  2.   

    如果num字段是数字类型,那可以用group by -a.num来解决。
    但我觉得这个问题用cursor来解决效率可能更高,在cursor定义中是可以使用order by的。
      

  3.   

    那要是字符怎么办?我不能用cursor.因为我写在ASP里的.多谢指点
      

  4.   

    按照您的写法 select * from (select * frpm table a group by -a.num) where rownum<6 好象SQL*PLUS报错了...怎么写啊...这个-是负号的意思吗
      

  5.   

    这么写当然是不对的,应该写成
    select * 
      from (select -num, col1, col2, col3, ...
              from table a
             group by -a.num, col1, col2, col3, ...)
     where rownum < 6;
    group by 后面必须加上所有select中的字段。另外,在程序中是很忌讳写select *这样的语法的,会给你的debug带来很多麻烦。asp中也可以使用cursor返回记录集,参见:
    http://www.vbip.com/books/1861001789/chapter_1789_09.asp