BMS-HOSxP Community
HOSxP => MySQL => ข้อความที่เริ่มโดย: panus_t ที่ กรกฎาคม 08, 2014, 09:30:57 AM
-
สงสัย 2 คำสั่งนี้หา VN ได้ไม่เท่ากันครับ
1.คำสั่งจาก Custom Search จะได้ VN=114,887
select pt.*,ov.*
from vn_stat ov ,patient pt ,ovst ovst
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2007-10-01" and "2008-09-30" and ov.hn=pt.hn
2.คำสั่งเขียนเอง จะได้ VN=118,343
select count(v.vn) as countVN
from ovst o
left outer join vn_stat v on v.vn=o.vn
where v.vstdate between "2007-10-01" and "2008-09-30"
;D
-
สงสัย 2 คำสั่งนี้หา VN ได้ไม่เท่ากันครับ
1.คำสั่งจาก Custom Search จะได้ VN=114,887
select pt.*,ov.*
from vn_stat ov ,patient pt ,ovst ovst
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2007-10-01" and "2008-09-30" and ov.hn=pt.hn
2.คำสั่งเขียนเอง จะได้ VN=118,343
select count(v.vn) as countVN
from ovst o
left outer join vn_stat v on v.vn=o.vn
where v.vstdate between "2007-10-01" and "2008-09-30"
;D
คนละตาราง ต้องนับจากตารางเดียวกันสิครับ
-
สงสัย 2 คำสั่งนี้หา VN ได้ไม่เท่ากันครับ
1.คำสั่งจาก Custom Search จะได้ VN=114,887
select pt.*,ov.*
from vn_stat ov ,patient pt ,ovst ovst
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2007-10-01" and "2008-09-30" and ov.hn=pt.hn
2.คำสั่งเขียนเอง จะได้ VN=118,343
select count(v.vn) as countVN
from ovst o
left outer join vn_stat v on v.vn=o.vn
where v.vstdate between "2007-10-01" and "2008-09-30"
;D
คนละตาราง ต้องนับจากตารางเดียวกันสิครับ
นับจากตาราง VN_Stat เหรอครับ
select count(v.vn) as countVN
from vn_stat v
left outer join ovst o on o.vn=v.vn
where v.vstdate between "2007-10-01" and "2008-09-30"
แบบนี้ก็ได้ 118,343 เหมือนเดิม
หรือว่าผมยังไม่เข้าใจ ???
-
118,343 ตรงกัน ก็ถูกต้องแล้วนี่คัรบ..
นับจากตารางไหน ก็ต้องได้ผลลัพธ์เดียวกันจาก SQL Count(vn)
แต่โพสต์แรก มันคนละตาราง คนละรูปแบบ SQL