我一直在抨擊我的頭這一段時間現在我越來越行不通快;數據必須保持在行級別。TSQL保持有效複製和刪除無效的重複
我想保持與最早到達時,重複有效的數據。 Load1表示一個batchID。並不是所有的值有重複
我想回到
Code1 Code2 Code3 Load1 LoadTime
a1 a1 a1 1 2013-09-10
a1 a1 a1 1 2013-09-10
a1 a1 a1 1 2013-09-10
a2 a1 a1 2 2013-09-12
a1 a2 a1 3 2013-09-13
a1 a2 a1 3 2013-09-13
有什麼建議?
CREATE TABLE #Test (
Code1 varchar(10),
Code2 varchar(10),
Code3 varchar(10),
Load1 varchar(10),
LoadTime DATE
)
INSERT INTO #Test
VALUES ('a1','a1','a1','1','2013-09-10') --Keep
INSERT INTO #Test
VALUES ('a1','a1','a1','1','2013-09-10') --Keep
INSERT INTO #Test
VALUES ('a1','a1','a1','1','2013-09-10') --Keep
INSERT INTO #Test
VALUES ('a1','a1','a1','2','2013-09-11') --Delete
INSERT INTO #Test
VALUES ('a2','a1','a1','2','2013-09-12') --Keep
INSERT INTO #Test
VALUES ('a2','a1','a1','3','2013-09-13') --Delete
INSERT INTO #Test
VALUES ('a1','a2','a1','3','2013-09-13') --Keep
INSERT INTO #Test
VALUES ('a1','a2','a1','3','2013-09-13') --Keep
INSERT INTO #Test
VALUES ('a1','a2','a1','4','2013-09-13')-- Delete
INSERT INTO #Test
VALUES ('a1','a2','a1','4','2013-09-13')-- Delete
什麼是無效的重複? –
我意識到我已經非常嚴肅地問了這個問題。我將不得不重寫它。謝謝 – pekingducksoup