ประมาณนี้ไหมครับ
select pt.name As pttype_name,count(distinct (v.hn)) As cc from vn_stat v
left outer join ovst o on(v.vn=o.vn)
left outer join pttype pt on(v.pttype=pt.pttype)
where v.vstdate between "2011-05-01" and "2012-05-31"
and o.main_dep="002"
group by v.pttype
select pt.name As pttype_name,count(distinct (v.vn)) As cc from vn_stat v
left outer join ovst o on(v.vn=o.vn)
left outer join pttype pt on(v.pttype=pt.pttype)
where v.vstdate between "2011-05-01" and "2012-05-31"
and o.main_dep="002"
group by v.pttype
select i.name As pdx_name,count(distinct (v.hn)) As cc from vn_stat v
left outer join ovst o on(v.vn=o.vn)
left outer join icd101 i on(v.pdx=i.code)
where v.vstdate between "2011-05-01" and "2012-05-31"
and o.main_dep="002"
group by v.pdx
select i.name As pdx_name,count(distinct (v.vn)) As cc from vn_stat v
left outer join ovst o on(v.vn=o.vn)
left outer join icd101 i on(v.pdx=i.code)
where v.vstdate between "2011-05-01" and "2012-05-31"
and o.main_dep="002"
group by v.pdx