sqlserver 查询重复数据

Posted spinoza

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver 查询重复数据相关的知识,希望对你有一定的参考价值。

 1 use StudentManageDB
 2 go
 3 insert into ScoreList (StudentId,CSharp,SQLServerDB)values(100006,52,80)
 4 insert into ScoreList (StudentId,CSharp,SQLServerDB)values(100007,91,66)
 5 insert into ScoreList (StudentId,CSharp,SQLServerDB)values(100009,78,35)
 6 
 7 select * from ScoreList order by StudentId
 8 
 9 --在知道那个字段重复的情况
10 select StudentId from ScoreList  group by StudentId having COUNT(*)>1
11 
12 --查询所有重复的记录
13 select * from ScoreList
14 where StudentId in(select StudentId from ScoreList  group by StudentId having COUNT(*)>1)
15 order by StudentId
16 
17 --其他方法
18 select * from ScoreList
19 where (select COUNT(*) from ScoreList  s where s.StudentId=ScoreList.StudentId)>1
20 order by StudentId
21 
22 --过滤掉重复数据
23 select distinct StudentId,CSharp from ScoreList
24 
25 select distinct StudentId,CSharp,SQLServerDB from ScoreList

 

以上是关于sqlserver 查询重复数据的主要内容,如果未能解决你的问题,请参考以下文章

sqlserver多表查询

通过查询创建SQL Server的数据库脚本[重复]

sql一对多的查询代码怎么查?

sqlserver分页去重失效

sql查询去掉重复记录

mysql,sqlserver数据库去重