BMS-HOSxP Community
HOSxP => Report Exchange => ข้อความที่เริ่มโดย: panus_t ที่ พฤศจิกายน 25, 2013, 10:29:02 AM
-
ทำไมยอดรวม 2 คำสั่งนี้ถึงไม่เท่ากันครับ
1.ได้จำนวน 128,953
select count(*) from vn_stat where vstdate between "2012-10-01" and "2013-09-30"
2.ได้จำนวนรวม 126,914
select o.main_dep,k.department,count(o.main_dep) as count_main_dep
from vn_stat v
left outer join ovst o on o.vn=v.vn
left outer join kskdepartment k on k.depcode=o.main_dep
where v.vstdate between "2012-10-01" and "2013-09-30"
group by o.main_dep
ต่างกันตั้ง 2,039
-
ทำไมยอดรวม 2 คำสั่งนี้ถึงไม่เท่ากันครับ
1.ได้จำนวน 128,953
select count(*) from vn_stat where vstdate between "2012-10-01" and "2013-09-30"
2.ได้จำนวนรวม 126,914
select o.main_dep,k.department,count(o.main_dep) as count_main_dep
from vn_stat v
left outer join ovst o on o.vn=v.vn
left outer join kskdepartment k on k.depcode=o.main_dep
where v.vstdate between "2012-10-01" and "2013-09-30"
group by o.main_dep
ต่างกันตั้ง 2,039
น่าจะมีข้อมูลว่างใน o.main_dep
-
;D ;D
-
;D ;D
??? ??? ลอง count ตรงๆจาก จาก vn_stat โดยไม่ต้องจอยกะตาราง ovst และ group by o.main_dep ดูซิครับว่า ผลเป็นยังงัยครับ ???
-
เปลี่ยนจาก count(o.main_dep) เป็น count(o.vn) ซิครับ
จะได้เห็นว่าที่ไม่มี main_dep มีแยอะแค่ไหน
-
เปลี่ยนจาก count(o.main_dep) เป็น count(o.vn) ซิครับ
จะได้เห็นว่าที่ไม่มี main_dep มีแยอะแค่ไหน
ลองแล้วเยอะจริง ๆ ด้วยครับ ตัวเลข 2 คำสั่งนี้เริ่มเท่ากันแล้วห่างแค่ 3 เนื่องจากมี vn ใน vn_stat แต่ไม่มีใน ovst ครับ ;D
ขอบคุณครับ ;D
-
ปกติ main_dep ควรจะมีข้อมูล ไม่ควรเป็นค่าว่าง
อาจจะเกิดจากการลงทะเบียนล่วงหน้าเป็นชุด