select MAX(STUFF(( SELECT distinct ','+ dm.DonarName
FROM dbo.DonarMaster dm
JOIN dbo.PMFunder pmf on pmf.FunderId = dm.DonarMasterID
WHERE pmf.ProgramMasterID = pm.ProgramMasterID
FOR XML PATH(''), TYPE).value('.','VARCHAR(max)'), 1, 1, '') ) as "Funder"
,plgm.ProgramLaunchID
,sm_tmo.FirstName + ' ' + sm_tmo.LastName as "TMO"
,d.DistrictName as "Location"
,CONVERT(VARCHAR(12), pl.StartDate, 107) as "Project start date"
,COUNT (distinct plgm.GroupID) as "Target groups"
,SUM(case when plgm.ActivationDate IS NULL then 0 else 1 end) as "Active groups"
,COUNT (distinct plgm.GroupID) * plsm.TotalNosesssion as "Target (year)"
,'-' as "Target (YTD)"
,COUNT (a.TMOID) as "Actual"
from dbo.PLGroupMapping plgm
,dbo.ProgramLaunch pl
,dbo.ProgramMaster pm
,dbo.PMFunder pmf
,dbo.DonarMaster dm
,dbo.District d
,Magicbus.dbo.PLSessionMapping plsm
,dbo.StaffMaster sm_tmo
LEFT JOIN #r6a a
on a.TMOID = sm_tmo.StaffMasterID
where plgm.ProgramLaunchid = pl.ProgramLaunchID
and pl.ProgramMasterID = pm.ProgramMasterID
and pm.ProgramMasterID = pmf.ProgramMasterID
and pmf.FunderId = dm.DonarMasterID
and plgm.TMOID = sm_tmo.StaffMasterID
and pl.DistrictID = d.DistrictID
and plsm.ProgramLaunchID = plgm.ProgramLaunchID
group by
plgm.ProgramLaunchID
,sm_tmo.FirstName + ' ' + sm_tmo.LastName
,d.DistrictName
,pl.StartDate
,plsm.TotalNosesssion
order by COUNT (a.TMOID), plgm.ProgramLaunchID
我所需要的只是一些正确方向的指导,因为目前我觉得我无处可去。感谢您的帮助,非常感谢。顺便说一下,就像我上一个问题一样,这又是作业,所以请不要直接回答。