码迷,mamicode.com
首页 > 数据库 > 详细

sqlserver 查询重复数据

时间:2018-11-24 23:54:03      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:core   nbsp   arp   bsp   sha   pre   col   distinct   val   

 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 查询重复数据

标签:core   nbsp   arp   bsp   sha   pre   col   distinct   val   

原文地址:https://www.cnblogs.com/Spinoza/p/10013961.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!