3

我有这个 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;
4

1 回答 1

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;
于 2012-09-19T09:59:52.357 回答