如何在sql中进行分区工作。它给出了附近的错误(

时间:2013-10-16 13:32:02

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

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中运行,但它在'('附近不断给出语法错误 无法弄清楚出了什么问题

1 个答案:

答案 0 :(得分: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