mysql删除重复的数据,保留一条,根据多个字段判断。以及统计重复数据

时间:2022-07-24 15:07:59

mysql根据两个字段判断重复的数据并且删除,只保留一条。

DELETE from table
where id Not IN
(select id from
(select MIN(id) as id,count(列1) as count from table
GROUP BY 列1,date
HAVING count(列1)>1) as temp);


MySQL统计重复数据,根据多条字段查询。

SELECT count(*),列1,列2,列3 from table
GROUP BY 列1,列2,列3 having count(*) > 1;