select
"Thai" as eclinic ,
"Medicine" as admitdepart,
i.*,
pcn.cardno as CID_CODE,
concat(pt.pname,pt.fname," ",pt.lname) as PT_NAME,
concat(pt.addrpart," ËÁÙè ",pt.moopart," µ.",t3.name," Í.",t2.name," ¨.",t1.name) as ADDRESS,
sx.name as SEX_NAME,
mr.name as MARRYSTATUS,
oc.name as OCCUPATION,
pt.birthday as DOB,
pt.informname as INFORMNAME,
concat("<",pt.informrelation,">") as INFORMRELATION,
pt.informaddr as INFORMADDR,
pty.name as PTTYPENAME,
wd.name as WARD_NAME,
sp.name as SPCLTY_NAME,
dc.name as DOCTOR_NAME
from an_stat i
left outer join ptcardno pcn on pcn.hn=i.hn and pcn.cardtype="01"
left outer join patient pt on pt.hn=i.hn
left outer join sex sx on sx.code=pt.sex
left outer join marrystatus mr on mr.code=pt.marrystatus
left outer join occupation oc on oc.occupation=pt.occupation
left outer join pttype pty on pty.pttype=i.pttype
left outer join ward wd on wd.ward=i.ward
left outer join spclty sp on sp.spclty=i.spclty
left outer join ovst ov on ov.an = i.an
left outer join doctor dc on dc.code = ov.doctor
left outer join thaiaddress t1 on t1.codetype="1" and t1.chwpart=pt.chwpart
left outer join thaiaddress t2 on t2.codetype="2" and t2.chwpart=pt.chwpart and t2.amppart=pt.amppart
left outer join thaiaddress t3 on t3.codetype="3" and t3.chwpart=pt.chwpart and t3.amppart=pt.amppart
and t3.tmbpart=pt.tmbpart
where i.an="510000001"
limit 1
ลองไปใช้ดูนะครับ คิดว่าน่าจะใช้ได้ ลองดูนะครับ เพิ่มฟิลด์ ชื่อหมอให้แล้วครับ
เดี๋ยวค่อยแปลทีละบรรทัด ลองใช้ดูก่อนนะครับ