BMS-HOSxP Community
HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bond_007 ที่ มิถุนายน 29, 2010, 09:16:28 AM
-
คำสั่งเปรียบเทียบตาราง opitemrece และ doctor_fee_list รายการ DF มีที่ตาราง opitemrece แต่ไม่มีใน doctor_fee_list ต้องเขียนยังไงครับ ขอบคุณครับ
ของผมเขียนแบบนี้ มันไม่ถูกอะครับไม่ทรายว่าต้องแก้ตรงไหนครับ
select o.vn,o.hn,o.an,o.icode,n.name,o.unitprice,o.vstdate,o.vsttime,d.name,df.icode from opitemrece o
left outer join nondrugitems n on n.icode = o.icode
left outer join doctor d on d.code = o.doctor
left outer join doctor_fee_list df on df.vn = o.vn
where n.item_is_df = "Y" and o.vstdate between '2010-05-01' and '2010-05-30' and (df.icode is null or df.icode = ' ')
-
จากรูปมันจะอยู่ในตาราง opitemrece โดยรายการ DF คือ DF ฉีดยาเข้าข้อ และค่าบริการผู้ป่วยนอก นอกเวลาราชการ
-
จากรูปจะอยู่ในตาราง doctor_fee_list ซึ่งมันว่างเปล่า
-
ขออนุญาติดันครับ
-
คำสั่งเปรียบเทียบตาราง opitemrece และ doctor_fee_list รายการ DF มีที่ตาราง opitemrece แต่ไม่มีใน doctor_fee_list ต้องเขียนยังไงครับ ขอบคุณครับ
ที่รพ.ผม ไม่ได้ใช้ DF ไม่ค่อยรู้เรื่อง data dic ของระบบนี้
แต่ถ้า "รายการ DF มีที่ตาราง opitemrece แต่ไม่มีใน doctor_fee_list ต้องเขียนยังไงครับ ขอบคุณครับ
" อาจจะลองเขียนแบบ select ซ้อน select แบบประมาณนี้ได้หรือเปล่าลองดูละกันนะครับ
select * from opitemrece where "field df ที่มีในตาราง opitemrece" not in (select "field df ที่อยู่ในตาราง doctor_fee_list" from doctor_fee_list )
ลองดูนะครับ มือใหม่เหมือนกันครับ
-
หรือว่าจะเป็น select * from opitemrece where icode not in (select icode from doctor_free_list) and rxdate between '2010-06-20' and '2010-06-25'
-
เหมือนจะไม่ได้ครับ
หรือว่าจะเป็น select * from opitemrece where icode not in (select icode from doctor_free_list) and rxdate between '2010-06-20' and '2010-06-25'
-
ขอบคุณครับที่แนะนำมากๆ
-
ผมลองเขียนคำสั่งใหม่
select o.hn ,concat (p.pname,p.fname," ",p.lname) as '????-????',pt.name as '?????',o.vstdate, o.icode ,n.name,doc.icode,d.name
from opitemrece o
left outer join nondrugitems n on n.icode = o.icode
left outer join patient p on p.hn = o.hn
left outer join doctor d on d.code = o.doctor
left outer join pttype pt on pt.pttype = o.pttype
left outer join doctor_fee_list doc on doc.vn = o.vn
where n.item_is_df='Y'
and vstdate between '2011-02-01' and '2011-02-31'
and o.icode <> doc.icode
ปรากฎว่ามีค่าบางตัวที่ไม่ถูกต้องตามรูปครับคือ icode ทั้งสองค่ามีเหมือนกันแต่อยู่คนละบรรทัดกันมันเลยดูไม่ถูกต้องไม่ทราบว่าต้องแก้ยังไงครับ