select
GroupNum,Type,
stuff(
(select ','+Name
from ProjectRelation rela
left join AccountMedia media on media.id=rela.AccountMediaID
where rela.GroupNum = relamain.GroupNum and rela.Type = relamain.Type and rela.ProjectID = relamain.ProjectID
for xml path('')), 1, 1, '')as 'AccountMedias'
from ProjectRelation relamain
where ProjectID = 7 group by GroupNum,Type,ProjectID