子查询中不能包含order by

博客转自:http://blog.csdn.net/cynhafa/article/details/8183083


===================================博客原文======

今天做开发遇到一个问题:写sql语句:

select  top 20 * from (select top 200 * from ump_user order by id)ttnn 

sql查不出来   因为子查询中不能包含order by 子句


具体原因:
在8i以前,子查询中不能包含Order By子句。

从8i开始,子查询可以有Order By,但必须是有top-n的这种子查询时才能用。

所谓的top-N查询就是:
TOP-N一般是指最大的n条记录或着是最小的n条记录。
如:
    select rownum , t.col1, t.col2, ... from  
    ( select col1, col2, ... from tab  
      order by col1 ) t  
    where rownum <= n;  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章