删除重复记录

Id    name     age      salary

1       yzk        80       1000

2       yzk        80        2000

3       tom       20        20000

4       tom       20        20000

5       im         20         20000

 

使用Distinct 去重:

SELECT DISTINCT Name FROM Persons(Distinct 只能去除结果集中一模一样的数据

 

获取不重复数据1:

SELECT Name, age FROM Persons GROUP BY Name, Gender

获取不重复数据2:

SELECT MAX(Id) AS Expr1, Name, Gender FROM Persons GROUP BY Name, age

 

获取不重复数据:

select * from Persons where Id in ( SELECT MAX(Id) AS Expr1 FROM Persons GROUP BY Name, age )

 

删除重复的数据:

delete from Persons where Id not in ( SELECT MAX(Id) AS Expr1 FROM Persons GROUP BY Name, age )

 

 

posted @ 2020-10-06 20:01  睡不醒的小韩  阅读(75)  评论(0编辑  收藏  举报