ลองอันนี้ดูครับ
select v.hn,concat(pname,fname,' ',lname) as name ,v.age_y,v.pdx ,v.vstdate
from vn_stat v
left outer join ovst o on o.vn=v.vn
left outer join patient p on p.hn = v.hn
where v.vstdate between'2007-10-01'and'2008-06-30'
and o.ovstist in ("XX","YY")
and lastvisit<=7 and old_diagnosis = 'Y'
and v.pdx not like'Z%' and v.pdx<>''
and o.main_dep='010'
order by v.vstdate