服务器 频道

用sql语句找出按某字段大小排列的5条记录

  【IT168 服务器学院】用sql语句如何找出数据库中按某字段大小排列的5条记录

  select * from ( select * from cpu order by cpuname) where rownum <6                               *

  ERROR 位于第 1 行:

  ORA-00907: 缺少右括号

  给子查询起个别名试试

  select * from ( select * from cpu order by cpuname) a where rownum <6

  Order by 不能加

  确实有点怪,除去ORDERBY就可以了

  oracle中在子查询中是不能用order by 语句的,不用尝试了

  不过可以用游标来实现的。

  SQL> select * from ( select * from tab order by tname) where rownum < 6;

  TNAME                          TABTYPE  CLUSTERID

  ------------------------------ ------- ----------

  A                              TABLE

  B                              TABLE

  C                              TABLE

  D                              TABLE

  E                              TABLE

  我的Oracle就支持Oracle 8.1.7

  你的ORACLE版本是什么?

  改用临时表吧。

  create table temp as ( select rownum row_no, * from cpu order by cpuname);

  select * from temp where row_no < 6;

  drop table temp;

0
相关文章