select o.vn,o.hn,o.o_refer_number,o.i_refer_number,d.name as doctor_name,o.vstdate,
o.vsttime,p.cid,concat(p.pname,p.fname,' ',p.lname) as ptname,
concat(h.hosptype,' ',h.name) as hospname,
r.name as refername, o.o_refer_dep as refer_dep,
ro.* ,s.name as sex ,vs.age_y , p.informaddr as address
from ovst o
left outer join patient p on p.hn=o.hn
left outer join vn_stat vs on vs.hn=p.hn
left outer join sex s on s.code=vs.sex
left outer join hospcode h on h.hospcode = o.rfrolct
left outer join rfrcs r on r.rfrcs = o.rfrocs
left outer join doctor d on d.code = o.doctor
left outer join referout ro on ro.vn=o.vn and ro.refer_number = o.o_refer_number
where o.vn="550223092111" and o.o_refer_number="5501107" order by o.vstdate,o.vsttime