冒牌兄的意思是这样的 select distinct a.name,b.telephone from a, (select customerid,stuff((select ','+telephone from b where customerid=t.customerid for xml path(''),1,1,'') as telephone from b t group by customerid)b where a.id=b.customerid
SELECT * FROM 表A a OUTER APPLY (SELECT phone=STUFF((SELECT ','+phone FROM 表B WHERE customerid = a.id FOR XML PATH('')),1,1,'')) b
select
distinct a.name,b.telephone
from
a,
(select customerid,stuff((select ','+telephone from b where customerid=t.customerid for xml path(''),1,1,'') as telephone
from b t group by customerid)b
where
a.id=b.customerid
FROM 表A a
OUTER APPLY
(SELECT phone=STUFF((SELECT ','+phone FROM 表B WHERE customerid = a.id FOR XML PATH('')),1,1,'')) b