使用TSQL,不知道如果Postgres支持用臨時表,但你可以選擇到一個臨時表,然後通過循環和刪除和插入您的結果放回原
-- **Disclaimer** using TSQL
-- You could select your records into a temp table with a pk
Create Table #dupes
([id] int not null identity(1,1), f1 int, f2 int, f3 int)
Insert Into #dupes (f1,f2,f3) values (1,2,3)
Insert Into #dupes (f1,f2,f3) values (1,2,3)
Insert Into #dupes (f1,f2,f3) values (1,2,3)
Insert Into #dupes (f1,f2,f3) values (2,3,4)
Insert Into #dupes (f1,f2,f3) values (4,5,6)
Insert Into #dupes (f1,f2,f3) values (4,5,6)
Insert Into #dupes (f1,f2,f3) values (4,5,6)
Insert Into #dupes (f1,f2,f3) values (7,8,9)
Select f1,f2,f3 From #dupes
Declare @rowCount int
Declare @counter int
Set @counter = 1
Set @rowCount = (Select Count([id]) from #dupes)
while (@counter < @rowCount + 1)
Begin
Delete From #dupes
Where [Id] <>
(Select [id] From #dupes where [id][email protected])
and
(
[f1] = (Select [f1] from #dupes where [id][email protected])
and
[f2] = (Select [f2] from #dupes where [id][email protected])
and
[f3] = (Select [f3] from #dupes where [id][email protected])
)
Set @counter = @counter + 1
End
Select f1,f2,f3 From #dupes -- You could take these results and pump them back into --your original table
Drop Table #dupes
測試這對MS SQL Server 2000.不熟悉Postgres的選項,但也許這會導致你在一個正確的方向。
我不確定我是否理解正確。你說「PK是3場」 - 那麼你怎麼像表1-2-3中的重複記錄一樣。糾正我,如果我錯了。 – 2008-10-28 15:02:00
PK是在3個領域,我們必須刪除他們的合併(長篇故事),現在我們需要把它放回去。我們有一些我們想要起飛的重複。 – 2008-10-28 15:10:31