เอาแบบนี้ได้ไหมครับ  
ความหมายคือ  จะ  count  ให้เป็นจำนวนคนใช่ไหมครับ
select count(*)as cc
from vn_stat  h
where h.hn in(select hn from lab_order ตารางนี้ไม่มี  hn ครับ
where confirm="Y" and lab_order_result<>'' and lab_order_result is not null
and vstdate between "2009-09-20" and "2009-09-24"   and lab_items_code in("66","3088") )
ปล.  แต่ถ้าเป็นแบบของคุณ atit  จะตัด  HN ที่มาซ้ำ 2 ครั้งออกนะ(ใช่ไหมครับ )   ***  ผลจะเท่ากับ 3
       แต่อันนี้จะไม่ตัดออก แต่นับเป็น 1 คน  ครับ                                               *** ผลจะเท่ากับ 4
    
เนื่องจากนับจาก vn_stat ที่มี hn ที่ดึงมาเลยนับมาหมดเลยมาตรวจอะไรก็นับหมดที่เป็น HN นี้ก็เลยไม่ตรงครับ
อ้อผมแก้ใหม่นะครับเป็น
select count(*)as cc
from vn_stat  v
where v.hn in(select h.hn from 
lab_head hleft outer join lab_order o1 on o1.lab_order_number=h.lab_order_number and o1.confirm="Y"
        and o1.lab_order_result<>"" and o1.lab_order_result is not NULL
        where  h.order_date between "2009-09-20" and "2009-09-24"   and o1.lab_items_code in("66","3088") )
แบบคุณอาร์มก็ได้ หรือถ้าต้องการแบบนี้ก็ลองไปใช้ดูครับ.... 
 
  a:= GetSQLSubQueryData('select h.hn  '+
       ' from lab_head h  '+
       ' left outer join lab_order o1 on o1.lab_order_number=h.lab_order_number and o1.confirm="Y"   '+
       ' and o1.lab_order_result<>"" and o1.lab_order_result is not NULL  '+
       ' where  h.order_date between "'+formatdatetime('yyyy-mm-dd',rxdate1)+'" and "'+
          formatdatetime('yyyy-mm-dd',rxdate2)+'"   and o1.lab_items_code in("4","15") '+
       ' group by h.hn  '+
       ' having count(h.hn) >= 2 ');
  Value :=GetSQLStringData('select count(distinct hn)as cc from lab_head where hn in('+a+') ') ;
ผมตั้ง a:string; นะครับเหมือนว่าจะได้แต่ก็นับได้แค่ 1 ครับน่าจะเท่ากับ 3ก็เลยยังงงอยู่เลย
a:= GetSQLSubQueryData('select count(h.hn)  '+
       ' from lab_head h  '+
       ' left outer join lab_order o1 on o1.lab_order_number=h.lab_order_number and o1.confirm="Y"   '+
       ' and o1.lab_order_result<>"" and o1.lab_order_result is not NULL  '+
       ' where  h.order_date between "'+ds1+'" and "'+ds2+'"   and o1.lab_items_code in("66","3088") '+
       ' group by h.hn  '+
       ' having count(h.hn) < 2 ');   
ผิดตรงใหนหรือเปล่าครับ 

ขอบคุณทุกท่านที่ตอบครับ
ยังรอคอยคำตอบต่อไป 
