select n.name,count(distinct o.hn) as PERSON
,count(distinct if(o.vn is null,o.an,o.vn))as VISIT
,sum(o.sum_price) as Total
,sum(if(o.paidst in (01,03),o.sum_price,0)) OK
,sum(if(o.paidst not in (01,03),o.sum_price,0)) NO
from opitemrece o
left outer join patient p on p.hn=o.hn
left outer join nationality n on n.nationality=p.nationality
where vstdate between "2014-10-01" and "2015-09-30"
and p.nationality <> "99"
group by p.nationality