分页查询

--------------------------oracle

1.select * from (
       select tb1.*,rownum rn from (
              select * from flow_task order by serialno
       ) tb1
       where rownum < 40
) tb2
where tb2.rn >30;

2.select * from (
       select tb1.*,rownum rn from (
              select * from flow_task order by serialno
       ) tb1
) tb2
where tb2.rn between 30 and 40;

注:对比这两种写法,绝大多数的情况下,第一个查询的效率比第二个高得多。

------------------------DB2

select * from (
        select tb1.*,rownumber()over() as rn from (
               select * from lc_appl order by appl_cde
        ) tb1
)tb2
where tb2.tn between 30 and 40;

 

posted on 2015-09-11 21:02  最不好  阅读(157)  评论(0)    收藏  举报

导航