如果有相同数据的话保留相同数据id为最大的,删除其他的数据。
delete a
from user a
left join
(select username, count(id), Max(id) as id
from user
group by username
having count(id) > 1) b
on a.username = b.username
where a.id < b.id;