日期:2014-05-17  浏览次数:21007 次

如何利用rownum取得查询出结果,并排过序的后几行数据
前几行的数据可以用
SQL code
SELECT *
  FROM (SELECT   col_1, col_2
            FROM my_table
        ORDER BY col_1)
 WHERE ROWNUM < 35


假如我有67条记录,后34行的数据应该怎样取得?是在排序的情况下

如果不用rownum有其他的方法可以取到吗?

------解决方案--------------------
select col_1, col_2
from 
(SELECT rownum as account, col_1, col_2
FROM my_table
ORDER BY col_1) a 
where account>34
看看行不行
------解决方案--------------------
探讨
select col_1, col_2
from
(SELECT rownum as account, col_1, col_2
FROM my_table
ORDER BY col_1) a
where account>34
看看行不行

------解决方案--------------------
SQL code
SELECT *
  FROM (SELECT   col_1, col_2
            FROM my_table
        ORDER BY col_1)
 WHERE ROWNUM < 67
minus
SELECT *
  FROM (SELECT   col_1, col_2
            FROM my_table
        ORDER BY col_1)
 WHERE ROWNUM < 33

------解决方案--------------------
类似

SQL code
select * from(
select a.*,row_number() over(order by object_id) as rn from dba_objects a
)where rn>64 and rn<=100

------解决方案--------------------
SQL code
 CREATE TABLE MG_CONT AS
    SELECT SYSDATE + LEVEL CONTRACT_ST_DATE FROM DUAL CONNECT BY LEVEL < 68;

------解决方案--------------------
探讨
类似


SQL codeselect * from(
select a.*,row_number() over(order by object_id) as rn from dba_objects a
)where rn>64 and rn<=100

------解决方案--------------------
3楼方法也可以啊