set @chw:=(select chwpart from hospcode where hospcode=(select hospitalcode from opdconfig));
select if(a.hospmain='99999','µèÒ§¨Ñ§ËÇÑ´',a.name) name,sum(a.rw<0.5) cc
from (select if(h.chwpart=@chw,o.hospmain,'99999') hospmain,h.name
,i.rw,i.dchdate
from ipt i
left join ovst o on o.vn=i.vn
left join hospcode h on h.hospcode=o.hospmain
left join pttype p on o.pttype=p.pttype
left join ipt_labour lr on lr.an=i.an
left join ipt_newborn nb on nb.an=i.an
where i.dchdate between '2012-10-1' and '2013-9-30'
and lr.an is null
and nb.an is null
and p.pttype_spp_id in (3,4)) a
group by hospmain