select custor,sum(zl),count(distinct xh) as jx ,xh=max(stuff( (selectdistinct','+xh from aaaa b where b.custor=a.custor for XML PATH('')) ,1,1,'')) from aaaa a groupby custor
select custor,sum(zl) zl,count(distinct xh) as jx
,xh=stuff( (select distinct ','+xh from tab_xh b
where b.custor=a.custor
for XML PATH('')),1,1,'')
from tab_xh a group by custor