统计每个部门中有多少人有某个项目 select * from
PeisPatientConclusion
inner join
PeisPatient
on
PeisPatientConclusion.ID_Patient=PeisPatient.ID_Patient
where Org_Name is not null
and DateFinalExamed>'2013-01-01' and DateFinalExamed<'2013-12-31'
and Conclusion_Name_R like '%峨眉山%'
order by Org_Name
;with t
as
(
select Org_Name,姓名 from
PeisPatientConclusion
inner join
PeisPatient
on
PeisPatientConclusion.ID_Patient=PeisPatient.ID_Patient
where Org_Name is not null
and DateFinalExamed>'2013-01-01' and DateFinalExamed<'2013-12-31'
and Conclusion_Name_R like '%峨眉山%'
)
select distinct
Org_Name,
replace(STUFF((select ','+姓名 from t t2
where t2.Org_Name = t1.Org_Name
for xml path('')
),1,1,''),',',' ')
from t t1