比如有个表A,表中有100000条记录,他有两个字段b,c,我现在想根据b排序来取第100到200条数据只取前N条数据是比较容易的,使用 select * from a where rownum<=100 order by b 可以在不使用任何索引的情况下,将速度提升到很高。但是rownum不支持>=,所以不能实现取一个范围。可以通过
select * from
(
select a.*,rownum r from a where rownum<=200 order by b
) where r<=N
来实现这个功能,但是随着N的增大,该表排序的时间会越来越长,当查询99990到第100000条记录时速度和全表排序差不多慢,请问各位有没有什么好的方法
select * from
(
select a.*,rownum r from a where rownum<=200 order by b
) where r<=N
来实现这个功能,但是随着N的增大,该表排序的时间会越来越长,当查询99990到第100000条记录时速度和全表排序差不多慢,请问各位有没有什么好的方法
FROM TestTable
WHERE (ID >
(SELECT MAX(id)
FROM (SELECT TOP 99990 id
FROM TestTable
ORDER BY id) AS T))
ORDER BY ID
FROM TestTable
WHERE (ID >
(SELECT MAX(id)
FROM (SELECT TOP 100000 id
FROM TestTable
ORDER BY id) AS T))
ORDER BY ID
select last_name,salary from employees order by nvl(salary,0) desc)) e
where r between 100 and 200;
select tt.* from
(
select rownum r,t.* from
(select * from A order by b) t
)tt
where tt.r>=100 and tt.r<=200