实例!

说明: guest库的tt表中有两个字段id和mobile, mobile字段中有重复的内容,目的删除重复的内容(重复的内容要留一个).


wKiom1LgsPTCnD7vAAA6bQ32cUU410.jpg









处理的结果如下:

wKiom1LgsgqDSBn5AAArA3cYTSY729.jpg

使用的sql server 语句是

delete from guest.tt where id NOT IN (select max(id) as id from guest.tt  WHERE mobile in (select mobile from guest.tt group by mobile HAVING COUNT(1) > 1) group by mobile ) and mobile in ( select mobile from guest.tt group by mobile HAVING COUNT(1) > 1 )