ลองดูครับ ไม่รู้ว่าถูกตามความต้องการหรือเปล่า
select p.hn,p.cid,concat(p.pname,p.fname,' ',p.lname),v.age_y,v.age_m,p.informaddr,o.icd10,o.icd103,o.vstdate,
concat(s.name,' ',s.strength,' ',s.units) as namedrug
from patient p
left outer join ovstdiag o on p.hn = o.hn
left outer join vn_stat v on p.hn = v.hn
left outer join opitemrece m1 on m1.vn= v.vn
left outer join an_stat a on a.an=m1.an
left outer join s_drugitems s on s.icode=m1.icode
left outer join drugusage d on d.drugusage=m1.drugusage
left outer join drugitems i on i.icode=m1.icode
where v.pdx between 'F00' and 'F99' and (v.vstdate between '2008-10-01' and '2009-09-30' )
group by p.hn
และอีกแบบ
select distinct p.hn,p.cid,concat(p.pname,p.fname,' ',p.lname),v.age_y,v.age_m,p.informaddr,o.icd10,o.icd103,o.vstdate,
concat(s.name,' ',s.strength,' ',s.units) as namedrug
from patient p
left outer join ovstdiag o on p.hn = o.hn
left outer join vn_stat v on p.hn = v.hn
left outer join opitemrece m1 on m1.vn= v.vn
left outer join an_stat a on a.an=m1.an
left outer join s_drugitems s on s.icode=m1.icode
left outer join drugusage d on d.drugusage=m1.drugusage
left outer join drugitems i on i.icode=m1.icode
where v.pdx between 'F00' and 'F99' and (v.vstdate between '2008-10-01' and '2009-09-30' )