ผมต้องการเพิ่มที่อยู่ ครับ เพิ่ม แล้วทำไมที่อยู่ไม่ออกอ่ะครับ
select pt.hn,concat(pt.pname,pt.fname,' ',pt.lname) as ptname, c.name as clinic_name, o.doctor, d.name as doctor_name,
concat(pt.addrpart,"
? ",pt.moopart," ?.",t3.name," ?.",t2.name," ?.",t1.name) as fulladdressname,
o.hn,o.vstdate,o.nextdate,o.nexttime,o.note,o.vn,k.department, count(v.hn) as visit_count
from oapp o
left outer join patient pt on pt.hn=o.hn
left outer join clinic c on c.clinic=o.clinic
left outer join doctor d on d.code=o.doctor
left outer join kskdepartment k on k.depcode = o.depcode
left outer join ovst v on v.vstdate=o.nextdate
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
and v.hn=o.hn where o.nextdate between '2011-08-01' and '2011-08-31'
and o.hn not in (select hn from ovst
where vstdate between '2011-08-01' and '2011-08-31' )
group by o.oapp_id,pt.pname,pt.fname,pt.lname,c.name,o.doctor,d.name , o.hn,o.vstdate,o.nextdate,o.nexttime,o.note,o.vn,k.department