กำลังทำอยู่เหมือนกันครับ แบบว่างงอยู่ไม่ใช่น้อยกับเงื่อนไขปลีกย่อย ซึ่งเอกสารประกอบค่อนข้างเข้าใจยากอยู่
แต่ลองเอา Query ไปดูครับ ถ้าได้แล้วก็เอามาลงมั่งนะ ผมก็ยังไม่ Complete เหมือนกัน
select *
from iptoprt io
where (io.icd9 between "9301" and "9309"
or io.icd9 between "9311" and "9319"
or io.icd9 between "9322" and "9329"
or io.icd9 between "9331" and "9339"
or io.icd9 in ("9381","9384","9394","9399","8703","9910"))
and io.icd9 not in ("9303","9306","9307","9308","9315","9326","9337")
and io.an in
(select i.an
from iptdiag id
left outer join ipt i on i.an = id.an
left outer join patient p on p.hn = i.hn
left outer join pttype pt on pt.pttype = i.pttype
where i.regdate between "2012-04-01" and "2013-03-31"
and
(
(id.diagtype = "1" and id.icd10 between "I60" and "I699")
or
(
(id.diagtype = "1" and id.icd10 in ("G810","G811","G819","G830","G831","G832","G833","G839")) and id.an in
(select an from iptdiag where diagtype <> "1" and icd10 between "I60" and "I699")
)
)
and (i.dchtype not in ("03","04","08","09") or (i.dchtype = "04" and timestampdiff(day,i.regdate,i.dchdate) > "3"))
)