//group by 分组 、having:对分组的数据按条件筛选 、count(code) > 1 :查询code数量大于1条的数据
select code from table_code group by code having count(code) > 1;
select code,name from table_code group by code,name having count(*)>1;
//删除code重复的值,保留id最小的一条 (保留最大的一条用max(id))
delete from table_code
where code in (select code from table_code group by code having count(code) > 1)
and id not in (select min(id) from table_code group by code having count(code) > 1)
sql查询重复的值,多列,删除重复的code的数据,并保留id最大的一条,或者最小的一条
最新推荐文章于 2023-05-26 16:41:49 发布