私は次のSQLを持っていて、それをページングする方法を知りたいです:
@skip
との変数が@top
あるので、ページをめくることができます..
SELECT ID FROM (
SELECT COUNT(*) AS ID, -1 AS [Weight]
FROM Employees i
INNER JOIN #WeightedIDs w
ON (i.ID = w.ID)
WHERE (i.DepartmentID = 10 and i.ShiftID = 2)
UNION ALL
SELECT i.ID, w.[Weight]
FROM Employees i
INNER JOIN #WeightedIDs w
ON (i.ID = w.ID)
WHERE (i.DepartmentID = 10 and i.ShiftID = 2)
) x
ORDER BY x.[Weight] ASC
アップデート:
私は次のものを持っていますが、まったく機能しません:
DECLARE @skip INT, @top INT
SET @skip = 30
SET @top = 100
;WITH PaginatedResults AS
(
SELECT ID, w.[Weight],
ROW_NUMBER() OVER (ORDER BY w.[Weight] ASC) AS RowNum
FROM Employees i
INNER JOIN #WeightedIDs w
ON (i.ID = w.ID)
WHERE (i.DepartmentID = 10 and i.ShiftID = 2)
)
SELECT ID FROM (
SELECT COUNT(*) AS ID, -1 AS [Weight]
FROM Employees i
INNER JOIN #WeightedIDs w
ON (i.IssueID = w.id)
WHERE FlightID > 2 and IssueID > 0
UNION ALL
SELECT ID, [Weight]
FROM PaginatedResults
WHERE RowNum >= @skip AND RowNum < @skip + @top
) x
ORDER BY x.[Weight] ASC