SQL Server 去重處理

2021-07-22 09:04:53 字數 1096 閱讀 3030

asbegin

set nocount on; --不返回計數,提高處理速度

set xact_abort on; --如果出錯,會將transcation設定為uncommittable狀態

begin tran

declare @fn varchar(200) --檔名

declare @rn int --記錄號

declare @xm varchar(200) --姓名

declare @lxdh varchar(200) --聯絡**

declare @bbzs int --本表總數

declare @bbqc int --本表去重

declare @glqc int --關聯去重

declare @bbys int --本表餘數

declare @ys int --餘數

-- 本表按姓名去重

open xm_cursor

fetch next from xm_cursor into @rn,@xm,@lxdh

while @@fetch_status = 0

begin

fetch next from xm_cursor into @rn,@xm,@lxdh

endclose xm_cursor

deallocate xm_cursor

-- 本表按聯絡**去重

open dh_cursor

fetch next from dh_cursor into @rn,@xm,@lxdh

while @@fetch_status = 0

begin

fetch next from dh_cursor into @rn,@xm,@lxdh

endclose dh_cursor

deallocate dh_cursor

set @bbqc = @bbzs - @ys

-- 對比總表去重

set @glqc = @ys - @bbys

begin

endcommit tran;

set nocount off;

end

sqlserver記錄去重

insert into employee select2,emp name gender department salary from employee select from select row number over partition by emp id order by emp id em...

SQL Server 幾種去重總結

sql 單錶 多表查詢去除重覆記錄 單錶distinct 多表group by group by 必須放在 order by 和 limit之前,不然會報錯 1.distinct distinct 用於返回唯一不同的值 distinct語法 select distinct 欄位名稱,欄位名稱 fro...

簡單去重比較 複雜資料去重處理

準備測試 const arr1 array.from new array 100000 item,index const arr2 array.from new array 50000 item,index console.log 開始測試 const start new date gettime ...