语法如下:
delete from Q_qq where ID not in(select min(ID) from Q_qq group by Qno having count(Qno)>=1)
数据库 【该表数据已经 20W 了】 :
这个怎么优化呢?服务器直接卡爆了
同时,多条件的去重对cpu几乎没有影响,语法如下:
delete tmp from( select row_num = row_number() over(partition by Qno,Qqno order by Qtime asc) from Q_qun where Qtime>getdate()-1) tmp where row_num > 1
数据库 【该表数据已经接近24W了】 :
------解决思路----------------------
先在(Qno,ID)上建联合索引
delete from Q_qq
where EXISTS (SELECT *
FROM Q_qq t
WHERE t.Qno = Q_qq.Qno
AND t.ID < Q_qq.ID)