删除重复记录的办法
1. 增加字段 flag
2. 标记不需要删除的记录
UPDATE Users
SET flag = 1
FROM (SELECT MAX(UserId) AS userid
FROM Users AS Users_1
GROUP BY UserName) AS a INNER JOIN
Users ON Users.UserId = a.userid
3.删除记录
DELETE FROM users WHERE flag IS NULL
2. 标记不需要删除的记录
UPDATE Users
SET flag = 1
FROM (SELECT MAX(UserId) AS userid
FROM Users AS Users_1
GROUP BY UserName) AS a INNER JOIN
Users ON Users.UserId = a.userid
3.删除记录
DELETE FROM users WHERE flag IS NULL