ลองใช้คำสั่งนี้ run กับคนไข้ที่มีปัญหาแล้วเบิ้ลไหมครับ
select r.group_id,r.group_name,sum(h1.rcptamt) as total1,sum(h2.rcptamt) as total2,
sum(h3.rcptamt) as discount ,h1.*,h2.*
from income_report2 r
left outer join income i on i.group2=r.group_id
left outer join incith h1 on h1.income=i.income and h1.an="ใส่เลข AN" and h1.paidst in ("01","00","02")
left outer join incith h2 on h2.income=i.income and h2.an="ใส่เลข AN" and h2.paidst in ("03")
left outer join rcpt_print_detail h3 on h3.income=i.income and h3.vn="ใส่เลข AN" and h3.paidst in ("04") where h1.income is not null or h2.income is not null
group by r.group_id, r.group_name
order by r.group_id
Bangkok Medical Software Call Center