您可以使用相关子查询。
delete * from yourtable a
inner join
(select fileid, first, last, amt, filldate
from yourtable
where fileid in (4028, 2090)
group by first, last, amt, filldate
having count(1) > 1) as duplicates
on (duplicates.first = a.first
and duplicates.last = a.last
and duplicates.amt = a.amt
and duplicates.filldate = a.filldate)
;
即使没有定义要删除的文件ID,这也会删除所有重复项:
delete * from yourtable a
inner join
(select min(id) minid, first, last, amt, filldate
from yourtable
group by first, last, amt, filldate
having count(1) > 1) as duplicates
on (duplicates.first = a.first
and duplicates.last = a.last
and duplicates.amt = a.amt
and duplicates.filldate = a.filldate
and duplicates.minid <> a.id)
;