Id name age salary
1 yzk 80 1000
2 yzk 80 2000
3 tom 20 20000
4 tom 20 20000
5 im 20 20000
a. 使用Distinct 去重:
SELECT DISTINCT Name FROM Persons(Distinct 只能去除结果集中一模一样的数据)
b. 获取不重复数据思考1:
SELECT Name, age FROM Persons GROUP BY Name, Gender
c. 获取不重复数据思考2:
SELECT MAX(Id) AS Expr1, Name, Gender FROM Persons GROUP BY Name, age
d. 获取不重复数据:
select * from Persons where Id in ( SELECT MAX(Id) AS Expr1 FROM Persons GROUP BY Name, age )
e. 删除重复的数据:
delete from Persons where Id not in ( SELECT MAX(Id) AS Expr1 FROM Persons GROUP BY Name, age )
删除姓名、年龄重复的记录
最新推荐文章于 2023-12-14 10:28:44 发布