[英]SQL query: how to convert varchar to signed integer for 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之前,通過對帶有IDENTITY
列的#temp
表中的有序插入來解決此問題域,以生成序列號。 這將解決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()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.