到目前为止,我有以下内容。
DECLARE @Table Table (ID int, Value1 varchar(50), Value2 varchar(50), Value3 varchar(50))
INSERT INTO @Table (ID, Value1, Value2, Value3)
SELECT 1, 'One', 'Uno', 'FIrst'
UNION ALL
SELECT 2, 'Two', 'Dos', 'Second'
UNION ALL
SELECT 3, 'One', 'Uno', 'Third'
UNION ALL
SELECT 4, 'Three', 'Tres', 'Fourth'
SELECT *, CASE
WHEN COUNT(*) OVER (PARTITION BY Value1, Value2) > 1 THEN 1
ELSE 0
END AS Duplicate FROM @Table
这给了我重复。我想再导出一个列,它将重复记录的连接值作为“第一 - 第三”(两列)
预期产出
ID Value1 Value2 Value3 Duplicate Value3
1 One Uno FIrst 1 First - Third
3 One Uno Third 1 First - Third
4 Three Tres Fourth 0 NULL
2 Two Dos Second 0 NULL