请考虑以下查询。
Select *
From table
Where name = 'stackoverflow'
Order By age
这是我感兴趣的查询。但是我也想将其与限制和偏移量结合起来。所以这就是我现在所做的。
Select
*,
ROW_NUMBER() OVER (ORDER BY primary_id DESC) as ROW_NUMBER
From
table
Where
name = 'stackoverflow'
Order By
age,
Offset 10 rows Fetch Next 20 Rows Only
问题是我得到了错误的结果。我想先根据where name = 'stackoverflow'
查询所有行,然后再查询order By age
,然后仅根据限制和偏移量获取一些行。
答案 0 :(得分:1)
您有两个order by
子句,也许您只需要一个:
select t.*
from table t
where name = 'stackoverflow'
order by age
offset 10 rows
fetch next 20 rows only;