a b c d 四個欄位
數值是 1 2 3 4
1 2 3 4
8 2 5 1
5 8 9 1
5 8 9 1
前兩行 和后兩行 資料都是完全一樣的,想實作:洗掉資料中完全一樣的,只保留像資料中不一樣的 如 上面的8 2 5 1,請大佬賜教
uj5u.com熱心網友回復:
select distinct a,b,c,d into new_table from tableuj5u.com熱心網友回復:
create table #t(a int,b int,c int,d int)
insert into #t(a,b,c,d)
select 1,2,3,4 union all
select 1,2,3,4 union all
select 8,2,5,1 union all
select 5,8,9,1 union all
select 5,8,9,1;
with t as
(select *,rn=row_number() over(order by getdate())
from #t)
delete x
from t x
where exists(select 1
from t y
where y.a=x.a and y.b=x.b and y.c=x.c and y.d=x.d
and y.rn<>x.rn)
select * from #t
/*
a b c d
----------- ----------- ----------- -----------
8 2 5 1
(1 行受影響)
*/
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/252875.html
標籤:基礎類
上一篇:Excel和SQL互動:無法初始化鏈接服務器 "(null)" 的 OLE DB 訪問介面 "Microsoft.ACE.OLEDB.12.0" 的資料源物件
