4
« เมื่อ: ธันวาคม 09, 2009, 13:33:58 PM »
รบกวนหน่อยครับลองทำแล้วไม่ออกครับ
select "INREGION" as inregion,
"FULL AGE" as fullage,
pt.hn as _hn_,ov.vsttime as _vsttime_,
ov.pttypeno as _PTTYPE_NO_,
ov.* ,pt.*,
concat(pt.pname,pt.fname," ",pt.lname) as fullname,
pty.name as pttypename,
t1.name as chwname,t2.name as ampname,
t3.name as tmbname,
concat(pt.addrpart," หมู่ ",pt.moopart," ต.",t3.name," อ.",t2.name," จ.",t1.name) as fulladdressname,
year(from_days(to_days(ov.vstdate)-to_days(pt.birthday))) as YearCount,
month(from_days(to_days(ov.vstdate)-to_days(pt.birthday))) as MonthCount,
dayofmonth(from_days(to_days(ov.vstdate)-to_days(pt.birthday))) as DayCount,
pcn.cardno as cid,
scn.*,sp.name as spname,
ph.*,
kp.department
from ovst ov
left outer join patient pt on pt.hn=ov.hn
left outer join pttype pty on pty.pttype=ov.pttype
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
left outer join ptcardno pcn on pcn.hn=ov.hn
left outer join opdscreen scn on scn.vn=ov.vn
left outer join spclty sp on sp.spclty=ov.spclty
left outer join kskdepartment kp on kp.depcode=ov.main_dep
left outer join pttypehistory ph on ph.hn=ov.hn and ph.pttype=ov.pttype
where ov.vn="450702091512"
order by expiredate desc
limit 1
ขอบคุณครับ