如何将此查询转换为 SQL Server 2000 语法

How to convert this query to SQL Server 2000 syntax

我 运行 这个查询 SQL Server 2008+ 但它在 SQL Server 2000 上不起作用。 我需要这个来执行。

WITH CTE AS ( 
    SELECT
        custnum,
        custname,
        RN = ROW_NUMBER() OVER( PARTITION BY custnum, custname ORDER BY custnum )
    FROM
        cust
)
SELECT
    *
FROM
    CTE
WHERE RN > 1

非常感谢您的帮助!

看看这是否有效

select custnum,custname from
(
select (select count(*) from cust as t1 where t1.custnum<=t2.custnum) as sno,
 custnum,custname from cust as t2
) as t
where sno>1

在 SQL Server 2005 之前,这个问题域通过有序插入 #temp table 和 IDENTITY 列来生成序列号来解决。这将解决 RANK()ROW_NUMBER() 要求。

例如:

    -- Create empty temp table
    SELECT custnum, custname, IDENTITY(INT, 1, 1) as RN
    INTO #cust
    FROM cust
    WHERE 0 = 1

    -- Populate with ORDER BY, to generate ascending RN
    INSERT INTO #cust
        (custnum, custname)
    SELECT
        custnum, custname
    FROM 
        cust
    ORDER BY
        custnum, custname

到那时,您可以为每个 custnum/custname 分组查询 MIN(),并像使用 CTE 一样使用它。

但是...ROW_NUMBER()真的是您想要的吗?似乎您想要 RANK(),而不是 ROW_NUMBER()