select v.hn ,count(v.vn) as visitcount ,
timestampdiff(year,p.birthday,now()) as age_y,
concat(p.pname,p.fname," ",p.lname)as ptname,
p.birthday,p.addrpart,p.moopart,a.full_name ,v.pttype ,p.cid
from vn_stat v
left outer join patient p on p.hn =v.hn
left outer join thaiaddress a on p.chwpart =a.chwpart and p.amppart = a. amppart and p.tmbpart=a.tmbpart
where v.vstdate between '2009-01-01' and '2009-01-05'
group by v.hn
having visitcount >= 2 and age_y >='60'
v.hn p.birthday v.vn
ไม่เข้าใจว่าทำไมต้องมี v. p. ข้างหน้าด้วยครับ