选择start,stop和rowcount,需要总计

时间:2012-09-19 09:35:10

标签: sql oracle

我有这个oracle sql,它为我提供了分页记录的子集。我还需要记录的总数,我可以将两个查询结合起来吗?真正的查询要复杂得多(与where等结合),我将其简化为不会分散我的问题。

select count(*) from table;
select outerfields.* from 
 (select row_number() over (order by id asc) r, innerfields.* from 
   ( (select * from table) innerfields)) outerfields where r between 1 and 10;

显然像下面这样的东西不起作用

select max(r), outerfields.* from 
  (select row_number() over (order by id asc) r, innerfields.* 
    from ( (select * from m30brief) innerfields)) outerfields where r between 1 and 10;

1 个答案:

答案 0 :(得分:1)

您可以将count(*) over()添加到outerfields派生表:

select outerfields.* 
  from 
  (
    select row_number() over (order by id asc) r, 
           count(*) over () totalRows,
           innerfields.* 
      from 
      (
        select * 
          from table
      ) innerfields
  ) outerfields
 where r between 1 and 10;