MySQL在DELETe语句中支持JOIN。如果要保留第一个重复项:
DELETE a FROM MYVIEWS a JOIN (SELECt MIN(t.a1) AS min_a1, t.k1, t.k2, t.k3 FROM MYVIEWS t GROUP BY t.k1, t.k2, t.k3 HAVINg COUNT(*) > 1) b ON b.k1 = a.k1 AND b.k2 = a.k2 AND b.k3 = a.k3 AND b.min_a1 != a.a1
如果要保留最后一个重复项:
DELETe a FROM MYVIEWS a JOIN (SELECt MAX(t.a1) AS max_a1, t.k1, t.k2, t.k3 FROM MYVIEWS t GROUP BY t.k1, t.k2, t.k3 HAVINg COUNT(*) > 1) b ON b.k1 = a.k1 AND b.k2 = a.k2 AND b.k3 = a.k3 AND b.max_a1 != a.a1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)