如何区分分页查询的结果?我想要使用SQL Server 2005分页方法
分页SELECT * FROM
(SELECT ROW_NUMBER() OVER (ORDER BY [dbo].[Tbl_Kartabl].[FKLoginID]) AS Row, [dbo].[Tbl_Kartabl].[FKLoginID]
FROM [dbo].[Tbl_Kartabl]) AS PagedResults
WHERE Row >= 1 AND Row <= 10
我该怎么做?
如何在SubSonic 2中实现此功能?
答案 0 :(得分:3)
在最里面的查询(from
子句)中,您需要使用select distinct
或使用group by
在排序之前仅提取唯一元素。
SELECT [Row], [FKLoginID]
FROM (SELECT ROW_NUMBER() OVER ( ORDER BY T.[FKLoginID]) AS Row, T.[FKLoginID]
FROM (SELECT DISTINCT [FKLoginID] FROM [dbo].[Tbl_Kartabl]) AS T ) AS PagedResults
WHERE Row >= 1 AND Row <= 10