--創建測驗表
create table test2
(
TestId UNIQUEIDENTIFIER not null ,
AddedOn varchar(50) not null,
Action varchar(50) not null,
Item int not null,
Parent int not null,
Param int not null,
BoolParam int not null,
Content int not null,
Proprties int not null,
)
SELECT * FROM dbo.test2
--新增測驗資料
INSERT INTO test2 VALUES (NEWID(),'1','1','1','1','1','1','1','1')
INSERT INTO test2 VALUES (NEWID(),'3','3','3','3','3','3','3','3')
--方法一 將某個欄位磁區進行排序,然后洗掉排序號為1以上的
DELETE T FROM (SELECT ROW_NUMBER() OVER(PARTITION BY Action ORDER BY Action) AS ROWNUMBER,* FROM test2 ) T
WHERE T.ROWNUMBER>1
--方法二 將某個欄位分組,查詢出條數大于1的最小主鍵,然后根據主鍵洗掉
DELETE t1
FROM test2 t1
WHERE t1.TestId >
(
SELECT MIN(t2.TestId)
FROM test2 t2
WHERE t1.Action = t2.Action
GROUP BY Action
HAVING COUNT(Action) > 1
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/233557.html
標籤:其他
上一篇:軟體設計師考試 | 第五章 軟體工程基礎知識 | 系統設計
下一篇:安碩資訊一面
