oracle先排序再分页
只做简单记录
按操作时间排序1
SELECT A.*, ROWNUM RN FROM (SELECT * FROM v_log) A ORDER BY operatetime DESC
结果
可以发现,按时间排序了,但是rownum并不是从小到大,因为oracle是先生成rownum,再进行排序,需要在套一层查询
按操作时间排序2
SELECT T.*, rownum RN FROM( SELECT * FROM (SELECT * FROM v_log) ORDER BY operatetime DESC ) T
结果
顺序正确,rownum正确,在此基础上再套一层查询进行分页
按操作时间排序并分页
SELECT T2.* from( SELECT T.*, rownum RN FROM( SELECT * FROM (SELECT * FROM v_log) ORDER BY operatetime DESC )T) T2 WHERE RN BETWEEN 1 and 10
结果
Become a Linux Programmer