41
« เมื่อ: กรกฎาคม 05, 2015, 12:51:29 PM »
select i.an,i.hn,concat(pt.pname,pt.pname,' ',pt.lname) ptname,pt.cid
,i.regdate,i.regtime,i.dchdate,i.dchtime
,inc.income_group income,g.name incomename
,oo.icode,concat(d.name,' ',d.strength) drug
,sum(oo.qty) qty
,oo.unitprice
,sum(if(oo.paidst=02,oo.sum_price,0)) 'OK'
,sum(if(oo.paidst<>02,oo.sum_price,0)) 'NOK'
,sum(oo.sum_price) total
from ipt i
join opitemrece oo on oo.an=i.an
join patient pt on i.hn=pt.hn
left join income inc on inc.income=oo.income
left join income_group g on inc.income_group=g.income_group
join s_drugitems d on oo.icode=d.icode
where i.an=580000001
group by oo.icode
order by income