我想在SQL查詢中進行分頁和排序。Row_Number()Over Order By計算機列
這裏是我的查詢
;WITH myCTE AS
(SELECT (FirstName+''+LastName) as [User Name],
ROW_NUMBER() OVER (ORDER BY FirstName) as RowID
From [MyTable])
SELECT TOP 10 * FROM myCTE
WHERE RowID > 10*(2-1)
它工作正常,但現在我想通過計算列[用戶名]
所以我改變了這樣的查詢
來記錄進行排序;WITH myCTE AS
(SELECT (FirstName+''+LastName) as [User Name],
ROW_NUMBER() OVER (ORDER BY [User Name] ASC) as RowID
From [MyTable])
SELECT TOP 10 * FROM myCTE
WHERE RowID > 10*(2-1)
但它給出了這個錯誤:
Msg 207, Level 16, State 1, Line 2
Invalid column name 'User Name'.
任何人都可以幫助我如何使用ROW_NUMBER()OVER計算列?或者我如何在SQL查詢中實現排序和分頁記錄?
謝謝你....這就是我想要的 – kombsh