------解决方案-------------------- select cid,snam from tb group by cid,snam having count(snam)>1 ------解决方案-------------------- select * from ( select rn = ROW_NUMBER() over (partition by class, name order by getdate()) * from #tb) a where rn >=2
不知道對不對 ------解决方案--------------------
select * from 学生名称表 a where exists (select 1 from 学生名称表 b where b.cid=a.cid and b.id<>a.id and b.snam=a.snam)