我想使用
在我的首页中显示第 1 到 50 项SELECT TOP(50) *
FROM Items_table
它工作正常,但我怎样才能获得下一页的第二个 50 项?查询应该如何?
请注意,我无法使用LIMIT
,因为我使用的是 SQL Server。
我也遇到以下查询问题:
select *
from (
select
ROW_NUMBER() over (
ORDER BY date_of_creation desc, time_of_creation desc) AS Row2,
*
from
Items_table) ir
where
ir.Row2 between @start and @end
问题在于此条件表适配器不支持OVER
。
表适配器是否支持其他 t-sql 代码?
最佳答案
如果您使用的是 SQL Server 2012 或更高版本,那么这将对您有所帮助
DECLARE @RowsPerPage INT = 50;
DECLARE @PageNumber INT = 2;
SELECT *
FROM ItemsTable
ORDER BY date_of_creation desc, time_of_creation desc
OFFSET (@PageNumber - 1) * @RowsPerPage ROWS
FETCH NEXT @RowsPerPage ROWS ONLY
变量@PageNumber
指定您要检索的页面(第一、第二......等)
关于asp.net - 提供第 n 页显示数据的最佳 t-sql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31096998/