我有一個名爲MyTable的與領域表ID(INT),姓名(NVARCHAR),值1(位),值2(位) EX:查找與扭曲的重複
1 Nathan True False
2 Nathan True False
3 John True False
4 John False True
,所以我可以很容易地找到名稱重複這樣的:
select 'First_Id'=a.Id,'First_Value1'=a.Value1,'First_Value2'=a.Value2,
'Second_Id'=b.Id,'Second_Value1'=b.Value1,'Second_Value2'=b.Value2
from MyTable a, MyTable b where a.Id>b.Id
and a.Name = b.Name
,然後我可以與標識在SecondId刪除的...
我想要做的就是找到重複的做一個邏輯或所有的之間重複組的值1,並用具有該值的副本更新每條記錄中的每條記錄,然後針對值2更新相同的記錄。
EX:
對於上面的例子中會有2組重複
的,其結果將是:
1 Nathan True False
2 Nathan True False
3 John True True
4 John True True
我怎樣才能做到這一點?
你是說,你要更新'Value1'和'Value2'每個組,使他們同在該組中的第一行? – imthepitts 2013-05-06 21:18:52