mysql根据多个字段删除重复记录,留下较大\较小id的值

根据3个字段删除重复记录,
delete from nb_mouldinfo_abnormal where ( modulno , lastUpdateTime, operate) in (select tt.modulno, tt.lastUpdateTime,tt.operate from ( select modulno, lastUpdateTime,operate from nb_mouldinfo_abnormal group by modulno, lastUpdateTime,operate HAVING count(1) >1 ) tt )
AND nbid NOT IN ( select aa.nbid from ( select max(nbid) nbid from nb_mouldinfo_abnormal group by modulno, lastUpdateTime,operate HAVING count(1) >1) aa )
–nbid:主键
max(nbid):留下大的id的值
min(id):反之

详细内容:https://blog.csdn.net/n950814abc/article/details/82284838

你可能感兴趣的:(数据库)