แบบนี้น่าจะใช้ได้ นะครับ
ลองปรับตามความต้องการดู ครับ
อ้าว! ถามเอง ตอบเอง
select l.form_name ,i.lab_items_name,count(o.lab_items_code) as count_order
from lab_form l
left outer join lab_items i on i.lab_items_code = l.lab_items_code
left outer join lab_order o on o.lab_items_code = i.lab_items_code
and o.lab_order_number in
( select lab_order_number from lab_head where (order_date
between "2009-07-01" and "2009-07-31")
and (sec_to_time(time_to_sec(report_time)-time_to_sec(order_time)) > '00:45:00')
and (department = 'OPD' )
)
group by l.form_name ,i.lab_items_name
order by l.form_name,i.lab_items_name