select i.dchdate, i.regdate,p.hn,rd.an,concat(trim(p.pname),trim(p.fname), " ",trim(p.lname)) as ptname, pt.name, ovst.hospmain ,concat(hospcode.hosptype,hospcode.name) as hname, Sum(rd.sum_price) AS price, a.paid_money, a.uc_money,a.remain_money ,discount_money ,rcpt_money,item_money,rcpno_list
from opitemrece rd
left outer join patient p on p.hn = rd.hn
left outer join an_stat a on a.an = rd.an
left outer join ipt i on i.an = a.an
left outer join pttype pt on i.pttype = pt.pttype
left outer join ovst on a.an = ovst.an
left outer join hospcode on ovst.hospmain = hospcode.hospcode
where a.dchdate between "2010-05-01" and "2010-05-31"
group by rd.an, pt.pttype
order by i.dchdate, pt.pttype
เพิ่มเลข13 หลัก
select vst.vstdate,vst.vn,vst.hn,concat(trim(pt.pname),trim(pt.fname), " ",trim(pt.lname)) as ptname,ptt.name as pttypename , vst.hospmain,
concat(hc.hosptype,hc.name) as hname,vst.income,vst.paid_money,vst.rcpno_list
from vn_stat vst
left outer join patient pt on vst.hn=pt.hn
left outer join pttype ptt on vst.pttype=ptt.pttype
left outer join hospcode hc on vst.hospmain = hc.hospcode
where vst.vstdate between '2010-05-01' and '2010-05-02'
order by vst.vstdate,vst.pttype
ถ้าจะเพิ่มเลข 13 หลัก จะต้องแทรกยังไงครับ