为什么'Invalid Column Name'
中的行号代表WHERE
。
SELECT Id, Name,
ROW_NUMBER() OVER (ORDER BY Id) AS 'RowNumber'
FROM Folks
WHERE RowNumber=3
虽然可以与ORDER BY
SELECT Id, Name
ROW_NUMBER() OVER (ORDER BY Id) AS 'RowNumber'
FROM Folks
ORDER BY RowNumber DESC
答案 0 :(得分:6)
试试这个:
SELECT *
FROM (SELECT Id, Name,
ROW_NUMBER() OVER (ORDER BY Id) AS 'RowNumber'
FROM Folks
) AS A
WHERE RowNumber = 3
答案 1 :(得分:3)
您缺少逗号:
SELECT f.*
FROM (SELECT Id, Name,
---------------------^
ROW_NUMBER() OVER (ORDER BY Id) AS RowNumber
FROM Folks f
) f
WHERE RowNumber = 3;
另外,您不能在同一级别的where
子句中使用列别名。子查询或CTE解决了这个问题。
而且,最好不要对列别名使用单引号。您应该仅对字符串和日期常量使用单引号。在这种情况下,rownumber
根本不需要转义。