SELECT vns.hn,vns.income, pt.pname, pt.fname, pt.lname,
concat(pt.addrpart,"
? ",pt.moopart," ?.",t3.name," ?.",t2.name," ?.",t1.name) as fulladdressname
, pt.cid, ovst.vstdate, ovst.vsttime
FROM vn_stat vns
LEFT OUTER JOIN patient pt ON pt.hn = vns.hn INNER JOIN
ovst ON ovst.vn = vns.vn
left outer join thaiaddress t1 on t1.chwpart=pt.chwpart and
t1.amppart="00" and t1.tmbpart="00"
left outer join thaiaddress t2 on t2.chwpart=pt.chwpart and
t2.amppart=pt.amppart and t2.tmbpart="00"
left outer join thaiaddress t3 on t3.chwpart=pt.chwpart and
t3.amppart=pt.amppart and t3.tmbpart=pt.tmbpart
WHERE vns.vstdate BETWEEN "2007-10-01" AND "2008-09-30" AND vns.pttype IN ("36")
GROUP BY vns.hn, pt.pname, pt.fname, pt.lname, pt.addrpart, pt.moopart,
pt.tmbpart, pt.amppart, pt.cid, ovst.vstdate, ovst.vsttime
ลงดู นะครับ