0

我有一个程序可以根据某些条件和特定顺序返回多行。这些行被分成几页(每页 50 行)。如何从具有某些特定行的页面中检索所有行。我创建了一个查询来完成这项工作,但它没有优化并且对性能有很大的影响。请帮助我优化它或提供替代方案:

select *
from
(
  select file_id, row_number() over (order by rownum) rn
  from my_table
)
where trunc(rn/50) = (
                      select trunc(rn/50) from 
                      (select t.*, rownum rn from my_table t)
                      where file_id = 29987);
4

1 回答 1

0

你得稍微调整一下...

with tab as
(
        -- the
        -- row_number() over (order by rownum) rn
        -- should be here
        select  level + 1000 as val
        ,       level/50     as rn_50
        from    dual
        connect by
                level < 140
)
, val as
(
        select  rn_50
        from    tab
        where   val = 1004 -- pg 1
        --where   val = 1051 -- pg 2
        --where   val = 1101 -- pg 3
)
select  *
from    tab t
where   rn_50 >= (select floor(rn_50) from val)
and     rn_50 <= (select ceil (rn_50) from val)
;
于 2013-09-03T10:19:11.563 回答