復制代碼 代碼如下:
public SeqList<int> Purge(SeqList<int> La)
{
SeqList<int> Lb = new SeqList<int>(La.Maxsize);
//將a表中的第1個數據元素賦給b表
Lb.Append(La[0]);
//依次處理a表中的數據元素
for (int i = 1; i <= La.GetLength() - 1; ++i)
{
int j = 0;
//查看b表中有無與a表中相同的數據元素
for (j = 0; j <= Lb.GetLength() - 1; ++j)
{
//有相同的數據元素
if (La[i].CompareTo(Lb[j]) == 0)
{
break;
}
}
//沒有相同的數據元素,將a表中的數據元素附加到b表的末尾。
if (j > Lb.GetLength() - 1)
{
Lb.Append(La[i]);
}
return Lb;
}
}
復制代碼 代碼如下:
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
復制代碼 代碼如下:
select * from test;select * from test group by id having count(*)>1select * from test group by idselect distinct * from testdelete from test a where a.rowid!=(select max(rowid) from test b where a.id=b.id);扯遠了,回到原來的問題,除了采用數據結構的思想來處理,因為數據庫特有的事務處理,能夠把數據緩存在線程池里,這樣也相當于臨時表的功能,所以,我們還可以用游標來解決刪除重復記錄的問題。
declare @max int,
@id int
declare cur_rows cursor local for select id ,count(*) from test group by id having count(*) > 1
open cur_rows
fetch cur_rows into @id ,@max
while @@fetch_status=0
begin
select @max = @max -1
set rowcount @max --讓這個時候的行數等于少了一行的統計數,想想看,為什么
delete from test where id = @id
fetch cur_rows into @id ,@max
end
close cur_rows
set rowcount 0 以上是閃電查閱一些資料寫出的想法,有考慮不周的地方,歡迎大家指出。
新聞熱點
疑難解答