Oracle 中使用带有 Order By 的分页处理办法

1. Oracle 分页中对于分页的处理,以下是没有 Order by 的正确分页Sql语句。
select * from
(
  SELECT rownum rownumber,a.id,a.userid,a.country,a.realname,a.firstname,a.lastname,a.educationbgcode,
  a.updatetime,round((sysdate-a.experienceyear)/360) as textint1,a.gender,a.birthday,a.educationbg,
  a.province,a.other,positiontype,positionsubtype
  FROM resume a
  where lang = '1'  AND a.isdeleted = '0'  AND a.educationbgcode>=4
  rownumber<=20
)
where  and rownum>10


2. Oracle 中分页语句中,有 order by 并且错误的查询将语句。
select * from
(
  SELECT rownum rownumber,a.id,a.userid,a.country,a.realname,a.firstname,a.lastname,a.educationbgcode,
  a.updatetime,round((sysdate-a.experienceyear)/360) as textint1,a.gender,a.birthday,a.educationbg,
  a.province,a.other,positiontype,positionsubtype
  FROM resume a
  where lang = '1'  AND a.isdeleted = '0'  AND a.educationbgcode>=4
  order by updatetime desc
  rownumber<=20
)
where  and rownum>10


3. 解决办法,将采用3次子查询来解决带有 Order by 的分页查询。SELECT x.* from
(  
  SELECT rownum numbers,z.* from
  (    
    SELECT rownum rownumber,a.id,a.userid,a.country,a.realname,a.firstname,a.lastname,a.educationbgcode,
    a.updatetime,round((sysdate-a.experienceyear)/360) as textint1,a.gender,a.birthday,a.educationbg,
    a.province,a.other,positiontype,positionsubtype
    FROM resume a
    where lang = '1'  AND a.isdeleted = '0'  AND a.educationbgcode>=4
    order by updatetime
  ) z
  where rownum<=10
) x   
where x.numbers>5

你可能感兴趣的:(oracle,sql,360)