有2种写法。今天学会一种新的。
先说下我们业务里的分页,取第20到第30行记录
select z.*
from (select p.*, rownum rn
from (select n.* from test n order by user_id) p where rn<=30) z
where rn >= 20
and rn <= 30
这种写法用了3个select,嵌套了2个select;
今天看到一种新的写法
select *
from (select n.*, row_number() over(order by user_id) rn from test n)
where rn>= 20
and rn<= 30
这种写法2个select搞定,好像要简洁一些。row_number() over(order by columnname) rn 这种排序函数以后可以尝试用一下。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25027760/viewspace-1061892/
,如需转载,请注明出处,否则将追究法律责任。