表中重复数据去重只保留一份(id较小的)

查询店员表w_other_empl中身份证号ss_id重复的数量

select t.ss_id,count(t.ss_id)  from w_other_empl t 
group by ss_id
having count(t.ss_id)>1
order by ss_id;

在这里插入图片描述

查询店员表w_other_empl中身份证号ss_id重复的数据较小的id,并删除id为其它的数据

delete from w_other_empl tt where tt.id not in(
select min(id) as t_id from w_other_empl t
group by ss_id
having count(t.ss_id)>1
);

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/axia1011/article/details/85318556