0
WITH xyz 
AS
(
    SELECT  col1, col2, col3, col4,
            ROW_NUMBER() OVER (PARTITION BY col1, col2, col3, col4 ORDER BY col1, col2, col3, col4) as RowNumber
    FROM  table1
 )

试图让上面的代码在 microsoft SQL 2008 中工作,但它在 '(' 附近不断给出语法错误,无法弄清楚出了什么问题

4

1 回答 1

0

我想你在这之后就使用了那个 CTE,所以尝试在WITH语句之前添加一个分号,如下所示:

;WITH xyz 
AS
(
    SELECT  col1, col2, col3, col4,
            ROW_NUMBER() OVER (PARTITION BY col1, col2, col3, col4 ORDER BY col1, col2, col3, col4) as RowNumber
    FROM  table1
)

使用 CTE 时,前面的语句必须用分号结束。如果您还没有这样做,请尝试SELECT * FROM xyz在右括号后添加。

于 2013-10-16T14:25:17.180 回答