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