0

SQL Server:使用 RowNo 重复结果集

SourceID    FullName    RowNo   UniqueID
----------------------------------------------------------------
29757   NORBERT OVERWEG 1   29757

53736   NORBERT OVERWEG 2   NULL

47636   NORBERT OVERWEG 3   NULL

25685   NORBERT OVERWEG 4   NULL

53579   NORBERT OVERWEG 5   NULL

42301   NORBERT OVERWEG 6   NULL

49717   SECION CHAN 1   49717

51212   SECION CHAN 2   NULL

如何用第 1 行中的相应 ID 替换 NULL?

预期结果:

SourceID    FullName    RowNo   UniqueID
-------------------------------------------------

29757   NORBERT OVERWEG 1   29757

53736   NORBERT OVERWEG 2   29757

47636   NORBERT OVERWEG 3   29757

25685   NORBERT OVERWEG 4   29757

53579   NORBERT OVERWEG 5   29757

42301   NORBERT OVERWEG 6   29757

49717   SECION CHAN 1   49717

51212   SECION CHAN 2   49717
4

1 回答 1

2

这应该有助于:

UPDATE MyTable a
set UniqueID = 
    (select uniqueid from MyTable b
     where rowno = 1 and a.FullName = b.FullName)
where UniqueID is null
于 2013-06-20T15:18:39.617 回答