1. 程式人生 > >sqlserver 查詢重復數據

sqlserver 查詢重復數據

pre from server sharp cor 方法 tin where 重復

 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 查詢重復數據