27,582
社区成员




declare @table table (ID int,UserName varchar(8),Tjr varchar(8))
insert into @table
select 1,'wang','11' union all
select 2,'a','wang' union all
select 3,'b','wang' union all
select 4,'zhangsan','22' union all
select 5,'c','zhangsan' union all
select 6,'d','zhangsan' union all
select 7,'lisi','33' union all
select 8,'e','lisi' union all
select 9,'f','lisi' union all
select 10,'kkk','wang'
select Tjr from @table group by Tjr having (count(1)>1)
/*
Tjr
--------
lisi
wang
zhangsan
*/
select * from tb
where username in (select Tjr from tb group by Tjr having count(1)>1)