– 分页
select * from t_user5
select count(1) from t_user5 --10,485,760
– rownum是一个查询后的结果,查询之前是不存在的
select rownum,rowid,tt.* from t_user5 tt
where rownum<=3 and sex=1 and rownum>=2
– 对结果进行查询
– 思路1,rownum的正确使用
– 缺点:
select * from (
select rownum myid,tt.* from t_user5 tt
) where myid>=2 and myid<=3
—改写:没排序
–1.高效率的取前N条
select rownum myid,tt.* from t_user5 tt
where rownum<=5
–2.高效的剔除前面2条
select * from (
select rownum myid,tt.* from t_user5 tt
where rownum<=5 – 第一层,无嵌套引用<=
) where myid>=3 – 第二层,嵌套,应用>=
– 有排序
select * from (
select rownum myid,pp.* from (
select * from t_user5 order by id asc – 正常的排序操作,不引用任何东西
) pp where rownum<=80 – 第2层,无嵌套引用<=
) where myid>=71 – 第3层,嵌套,引用>=