从子查询中选择时出现语法错误

时间:2012-10-15 03:54:53

标签: sql-server sql-server-2008 subquery

执行以下查询时出现语法错误?

select *
    from (select row_number() over (order by title) as RowNum  from question)
    where RowNum>5

任何人都知道如何修复它?

3 个答案:

答案 0 :(得分:1)

ALIAS提供给子查询,如下所示:

SELECT *
FROM (SELECT row_number() OVER (ORDER BY title) AS RowNum  FROM question) AS t1
WHERE RowNum>5

答案 1 :(得分:0)

如果您从子查询中的TABLE中选择了COLUMNS,那会有帮助吗?

select *
from (
    select *, row_number() over (order by title) as RowNum
    from question) SQ
where RowNum > 5

答案 2 :(得分:0)

;With CTE AS
(

    select row_number() over (order by title) as RowNum  from question
)
select * 
From Cte
Where RowNum > 5

OR

Select * From
(select row_number() over (order by title) as RowNum  from question)X
Where X.RowNum > 5