sql删除表中重复记录只保留一条记录

最终代码

update T_Fee set gzl_dfg_op = 'delete' 
where MetReadRecordID in
(
    select MetReadRecordID
    from T_Fee 
    where FeeItemID =2 and State =1 and MetReadRecordID is not null 
    group by MetReadRecordID
    having COUNT(MetReadRecordID)>1
)
and ID not in
(
    select min(ID)
    from T_Fee 
    where FeeItemID =2 and State =1 and MetReadRecordID is not null 
    group by MetReadRecordID
    having COUNT(MetReadRecordID)>1
)
原文地址:https://www.cnblogs.com/kimisme/p/5403353.html