34,576
社区成员
发帖
与我相关
我的任务
分享
if object_id('tb','U') is not null
drop table tb
go
create table tb
(
name varchar(10),
book varchar(10)
)
go
insert into tb
select '张三','' union all
select '李四','A' union all
select '李四','B' union all
select '王五','A' union all
select '王五','B'
go
;with cte (f1) as
(
select ','+name from tb group by name having count(1)=2 for xml path('')
)
select stuff(f1,1,1,'') from cte
go
SELECT [VALUE]=
STUFF((
SELECT ','+ A.NAME from TABLE A group by A.NAME having count(1)=2 FOR XML PATH('')),1,1,'')
select [name] from T group by [name] having count(1)=2
select [name] from Table group by book having count(1)=2