Попробуйте это ..
WITH MyTable AS
(
SELECT 1 Col1,CONVERT (VarChar (25), '0TY/OK') Col2 UNION ALL
SELECT 1,'0TY/OK' UNION ALL
SELECT 1,'0TY/OK' UNION ALL
SELECT 1,'0TY/OK' UNION ALL
SELECT 1,'0TY/OK' UNION ALL
SELECT 2,'2KP/L' UNION ALL
SELECT 2,'2KP/L' UNION ALL
SELECT 2,'2KP/L' UNION ALL
SELECT 2,'2KP/L' UNION ALL
SELECT 2,'2KP/L' UNION ALL
SELECT 3,'7U5/2M' UNION ALL
SELECT 3,'7U5/2M' UNION ALL
SELECT 3,'7U5/2M' UNION ALL
SELECT 3,'7U5/2M'
)
,
AllData AS
(
SELECT
*,
ROW_NUMBER () OVER (ORDER BY Col2) as Id
FROM MyTable
)
,
DistinctData AS
(
SELECT
Distinct Col2 AS Col3
FROM MyTable
),
DistinctWithRowNumber AS
(
SELECT
*,
ROW_NUMBER () OVER (ORDER BY Col3) as Id
FROM DistinctData
)
SELECT
Col1,
Col2,
Col3
FROM AllData
LEFT JOIN DistinctWithRowNumber
ON AllData.Id = DistinctWithRowNumber.Id
возвращает этот результат
Col1 Col2 Col3
----------- ------------------------- -------------------------
1 0TY/OK 0TY/OK
1 0TY/OK 2KP/L
1 0TY/OK 7U5/2M
1 0TY/OK NULL
1 0TY/OK NULL
2 2KP/L NULL
2 2KP/L NULL
2 2KP/L NULL
2 2KP/L NULL
2 2KP/L NULL
3 7U5/2M NULL
3 7U5/2M NULL
3 7U5/2M NULL
3 7U5/2M NULL