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

时间:2023-12-24 19:54:19

最终代码

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
)