ROW_NUMBER分页
Posted 分而治之
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ROW_NUMBER分页相关的知识,希望对你有一定的参考价值。
var query = string.Format("SELECT {0} FROM (SELECT ROW_NUMBER() OVER (ORDER BY {3}) AS RowNum, {0} FROM {4} where {5}) AS Paged WHERE RowNum >= {1} AND RowNum < {2} ORDER BY RowNum", columns, (pageSize-1)*pageIndex,pageSize*pageIndex, orderBy, tableName, where);
SELECT *
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY InsertDate) AS RowNum, *
FROM Posts
WHERE InsertDate >= ‘1900-01-01‘
) AS result
WHERE RowNum >= 1 // *your pagination parameters
AND RowNum < 20 //*
ORDER BY RowNum
================================
sqlserver 2012
SELECT * FROM [Posts]
ORDER BY [InsertDate]
OFFSET 20 ROWS
FETCH NEXT 5 ROWS ONLY
以上是关于ROW_NUMBER分页的主要内容,如果未能解决你的问题,请参考以下文章
分页查询的两种方法(双top 双order 和 row_number() over ())
SQL分页查询,纯Top方式和row_number()解析函数的使用及区别