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
)
posted @ 2016-04-18 10:03  Kimisme  阅读(330)  评论(0编辑  收藏  举报