select o.hn,ifnull(o.an,'') AN,concat(p.pname,p.fname," ",p.lname) as ptname
,o.vstdate,ptt.pttype,ptt.name pttypename
,v.income,v.uc_money,v.paid_money,v.remain_money
,if(v.income=v.uc_money+v.paid_money+v.remain_money,'','Error') 'Check'
from ovst o
left outer join vn_stat v on v.vn=o.vn
left outer join patient p on p.hn=v.hn
left outer join pttype ptt on ptt.pttype=v.pttype
where o.vstdate between '2012-10-01' and '2012-10-31'
order by o.hn,o.vn