日期:2014-05-18 浏览次数:20587 次
select h.hospitalname,i.illTypeName, isnull(p.[有取药记录的人数],0) as [有取药记录的人数], isnull(p.[没有取药记录的人数],0) as [没有取药记录的人数] from illType i Cross join hospital h left join (select illtypeID1,p.hospitalid, sum(case when P2.patientID is not null then 1 else 0 end) as [有取药记录的人数], sum(case when P2.patientID is null then 1 else 0 end) as [没有取药记录的人数] from patient_info as p left join payInfo as P2 on P2.patientID=p.patientID group by illtypeID1,p.hospitalid )p on p.illtypeID1 = i.illtypeID and h.hospitalid = p.hospitalid