码迷,mamicode.com
首页 > 其他好文 > 详细

ROW_NUMBER分页

时间:2016-03-26 17:19:39      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

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分页

标签:

原文地址:http://www.cnblogs.com/imust2008/p/5323215.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!