单主键
with T as( SELECT ROW_NUMBER() over (PARTITION By 工件号 order by 检测时间 desc) as rowid,* FROM 检测表 ) delete from T where id not in( select id from T where rowid = 1)
组合主键
with T as( SELECT ROW_NUMBER() over (PARTITION By MachineCode,Content,CreationTime order by id ) as rowid,* FROM [OperationRecords2021-03-01] ) delete from T where id not in( select id from T where rowid = 1)