row_number()分页返回结果顺序不确定
select top [PageSize] * from ( select row_number() over (order by id desc) as RowNum,* from table ) as A where RowNum > (PageIndex - 1) * PageSize
发现查询出来的结果顺序是不确定的,查询官方文档(地址:https://docs.microsoft.com/en-us/sql/t-sql/functions/row-number-transact-sql?view=sql-server-2017)得到原因:
select * from ( select row_number() over (order by id desc) as RowNum,* from table ) as A where RowNum between (PageIndex - 1) * PageSize + 1 and PageIndex * PageSize order by RowNum asc