นอก CUP ในจังหวัด (นอกเขตอำเภอ ในจังหวัด)
select v.vstdate,p.cardno,concat(pt.pname,pt.fname," ",pt.lname) as ptname,
v.hn,v.pttype,v.pttypeno,v.pcode,v.income,v.uc_money,v.item_money,v.paid_money,
v.hospmain,v.hospsub
from vn_stat v
left outer join patient pt on pt.hn=v.hn
left outer join ptcardno p on p.hn=v.hn and p.cardtype='01'
left outer join ovst o on o.vn=v.vn
left outer join er_regist e on e.vn=v.vn
left outer join pttype p2 on p2.pttype=v.pttype
left outer join pcode pc on pc.code=v.pcode
where v.vstdate between '2010-01-01' and '2010-01-05'
and v.hospmain in (select hospcode from hospcode
where chwpart in
(select chwpart from hospcode where hospcode=(select hospitalcode from opdconfig limit 1) )
and amppart not in
(select amppart from hospcode where hospcode=(select hospitalcode from opdconfig limit 1) ) )and v.vn not in (select vn from an_stat)
and v.pcode in ('AA','AB','AC','AD','AE','AF','AG','AI','AJ','AK','UC','UB','UA')
and v.uc_money>0
order by v.vstdate,v.pttype