重复筛选
本帖最后由 lailai410 于 2012-11-20 16:40:38 编辑
我想筛选出每一单,有ID重复的单号。请问怎么筛选
--例如:
单号 ID
6921109062192 H123456
6921109062192 H123456
6921109062321 FW082679020506
6921109062321 FW072490010006
6921109063045 989419310173021242
6921109063045 PZ800946035000
DX123456 88997766
DX123456 88997766
------最佳解决方案--------------------我拿了两个数据来测了一下,应该没问题了
WITH huang ( 单号, ID )
AS ( SELECT '6921109062192' ,
'H123456'
UNION ALL
SELECT '6921109062192' ,
'H123456'
UNION ALL
SELECT '6921109062321' ,
'FW082679020506'
UNION ALL
SELECT '6921109062321' ,
'FW072490010006'
),
huang2
AS ( SELECT ROW_NUMBER() OVER ( PARTITION BY 单号, ID ORDER BY 单号 ) rid ,
*
FROM huang
)
SELECT *
FROM huang2
WHERE rid > 1
------其他解决方案--------------------select distinct 单号
from TB
where ID in (select ID from TB group by ID having COUNT(1)>1)
------其他解决方案--------------------按照那个,还是有ID没有重复的数据出来了
------其他解决方案--------------------SELECT *
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY 单号 ) id ,