... ลอง run คำสั่งข้างล่างดูนะครับ อาจใช้เวลาประมวลผลคำสั่งพอสมควร...
...
select o.icd10,i.name as icd10_name,count(distinct v1.hn) as "ปี48_คน",count(v1.hn) as "คน48_ครั้ง",
count(distinct v2.hn) as "ปี49_คน",count(v2.hn) as "ปี49_ครั้ง",
count(distinct v3.hn) as "ปี50_คน",count(v3.hn) as "ปี50_ครั้ง",
count(distinct v4.hn) as "ปี51_คน",count(v4.hn) as "ปี51_ครั้ง"
from ovstdiag o
left outer join icd101 i on i.code = o.icd10
left outer join vn_stat v1 on v1.vn = o.vn and v1.vn like '48%'
left outer join vn_stat v2 on v2.vn = o.vn and v2.vn like '49%'
left outer join vn_stat v3 on v3.vn = o.vn and v3.vn like '50%'
left outer join vn_stat v4 on v4.vn = o.vn and v4.vn like '51%'
where o.icd10 in (select code from icd101)
group by o.icd10
order by icd10