在不同的rownum选择中,Oracle

时间:2016-04-18 13:52:47

标签: sql oracle pagination rownum

我正在尝试对我的网页进行分页,

我正在使用此查询:

Select *
From   (
  Select Row_.*,
         Rownum Rownum_
  From   (
    Select Distinct(Qa.Question_Id) As Id
    From   Question Qa
    Where  Qa.Is_Deleted = 'F'
    And    Qa.Is_Answered = 'T'
    Order By Qa.Like_Count Desc
  ) Row_ 
  Where Rownum <= 10
) Where Rownum_ > 0

我的结果是

10662   1
11315   2
11142   3
13591   4
12344   5
12264   6
12186   7
11938   8
11183   9
10842   10

当我尝试在5个最大结果解决方案中进行分页时

Select *
From   (
  Select Row_.*,
         Rownum Rownum_
  From   (
    Select Distinct(Qa.Question_Id) As Id
    From   Question Qa
    Where  Qa.Is_Deleted = 'F'
    And    Qa.Is_Answered = 'T'
    Order By Qa.Like_Count Desc
  ) Row_ 
  Where Rownum <= 5
) Where Rownum_ > 0

结果:

10662   1
11315   2
11142   3
11183   4
10842   5

Select *
From   (
  Select Row_.*,
         Rownum Rownum_
  From   (
    Select Distinct(Qa.Question_Id) As Id
    From   Question Qa
    Where  Qa.Is_Deleted = 'F'
    And    Qa.Is_Answered = 'T'
    Order By Qa.Like_Count Desc
  ) Row_ 
  Where Rownum <= 10
) Where Rownum_ > 5

结果

12264   6
12186   7
11938   8
11183   9
10842   10

在第二和第三个脚本中,第三个脚本9,10 rownum中的Solution与第二个脚本4,5相同。

为什么解决方案不像第一个查询?如何正确地对我的查询进行分页?

0 个答案:

没有答案