sql server 根据某一个字段查询是否数据重复

1.查询某一个字段重复的条数
select Name from Student group by Name having count(Name) > 1
2.根据名称 和 最大id排序 删除
delete from Student
where Name in( select Name from Student group by Name having count(Name) > 1) and
ID not in(select max(ID) from Student group by Name having count(Name) > 1 )

你可能感兴趣的:(#,sqlserver篇)