BMS-HOSxP Community
HOSxP => MySQL => ข้อความที่เริ่มโดย: golf_pk ที่ สิงหาคม 05, 2015, 17:59:54 PM
-
จากรูป ผมเขียน code ถูกต้องไมครับ รึปรับตรงไหนบ้างครับ
-
select n.name,count(distinct o.hn) as PERSON,count(o.vn)as VISIT,sum(o.sum_price) as SUM 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
-
select n.name,count(distinct o.hn) as PERSON,count(o.vn)as VISIT,sum(o.sum_price) as SUM 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
count(o.vn)as VISIT จะได้เท่าจำนวน record ของ vn นั้น ๆ ใน opitemrece
ลองเปลี่ยนเป็น count(distinct o.vn)as VISIT
-
ไม่แยกผู้ป่วยนอก/ใน เหรอครับ
-
select n.name,count(distinct o.hn) as PERSON,count(o.vn)as VISIT,sum(o.sum_price) as SUM 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
count(o.vn)as VISIT จะได้เท่าจำนวน record ของ vn นั้น ๆ ใน opitemrece
ลองเปลี่ยนเป็น count(distinct o.vn)as VISIT
ครับ แล้ว code ที่ทำนี้ จะได้แค่ ค่าใช้จ่ายทั้งหมดครับ แล้วถ้าอยากได้ ค่าใช้จ่ายที่เก็บได้จริงละครับ จะต้องเพิ่มโค้ดแบบไหนดีครับ จอยกับตรารางไหนอีกไมครับ
-
ไม่แยกผู้ป่วยนอก/ใน เหรอครับ
โจทย์ไม่แยกนะครับ อยากได้รวมเลยครับ
-
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