ลองแบบนี้มั๊ย
select a.hospsub,ifnull(h.name,'อื่นๆ') name
,count(distinct a.hn) 'case',count(a.hn) 'visit'
,concat(count(distinct if(a.age_y between 0 and 2,a.hn,null)),'/'
,count(if(a.age_y between 0 and 2,a.hn,null))) age_0_2
,concat(count(distinct if(a.age_y between 3 and 5,a.hn,null)),'/'
,count(if(a.age_y between 3 and 5,a.hn,null))) age_3_5
,concat(count(distinct if(a.age_y between 6 and 12,a.hn,null)),'/'
,count(if(a.age_y between 6 and 12,a.hn,null))) age_6_12
,concat(count(distinct if(a.age_y between 13 and 59,a.hn,null)),'/'
,count(if(a.age_y between 13 and 59,a.hn,null))) age_13_59
,concat(count(distinct if(a.age_y>=60,a.hn,null)),'/'
,count(if(a.age_y>=60,a.hn,null))) age_60_more
from (select d.vn,d.hn,v.age_y,v.aid
,if(v.hospsub='' or v.hospsub is null,(select hospitalcode from opdconfig)
,if(v.hospsub in (select hcode from pcu_child),v.hospsub,'99999')) hospsub
from dtmain d
left join vn_stat v on d.vn=v.vn
where d.vstdate between '2013-1-1' and '2013-1-31') a
left join hospcode h on h.hospcode=a.hospsub
group by a.hospsub