adhoustonj
Member
- Local time
- Yesterday, 21:29
- Joined
- Sep 23, 2022
- Messages
- 195
Hello AWF,
I'm trying to optimize multiple queries such as this one below. Does anything jump out that would help optimize this? I've been using the link below and identified my problem queries that take the longest. I'd like to approach this to achieve the quickest possible query run time.
There are not millions of records in these tables - employees (10,000), hs_area_fields (2,000), hs_fields(35), hs_area_fields_trn(100,000)
Thanks
I'm trying to optimize multiple queries such as this one below. Does anything jump out that would help optimize this? I've been using the link below and identified my problem queries that take the longest. I'd like to approach this to achieve the quickest possible query run time.
There are not millions of records in these tables - employees (10,000), hs_area_fields (2,000), hs_fields(35), hs_area_fields_trn(100,000)
Speed tests and speed comparisons for everyone
The attached access file contains two tables, three queries, a module and a stopwatch class. If these elements are transferred to your own application, you will be able to carry out speed tests and speed comparisons for a large number of tasks without great effort. This solution is not as broad...
www.access-programmers.co.uk
Code:
SELECT afe.hs_area_id
, afe.hsf_id
, afe.hsaf_id
, Count(IIf([tr_date] Is Null And [str_date]<[tblHS_area_fields]![aud_date],1)) AS notrain
, Count(tblEmployees.emp_id) AS emp
, IIf([notrain]=0,1,1-[notrain]/[emp]) AS trn_per
FROM (tblHS_fields
INNER JOIN (((SELECT af.*, tblEmployees.emp_id
FROM (SELECT tblHS_area_fields.hs_area_id
, tblHS_area_fields.hsf_id
, Max(tblHS_area_fields.hsaf_id) AS hsaf_id
FROM tblHS_area_fields
GROUP BY tblHS_area_fields.hs_area_id, tblHS_area_fields.hsf_id) AS af
INNER JOIN tblEmployees ON af.hs_area_id = tblEmployees.hs_area_id
WHERE (((tblEmployees.obsolete)=No) AND ((tblEmployees.no_hs_rec)=No))) AS afe
LEFT JOIN tblHS_area_fields_trn ON (afe.emp_id = tblHS_area_fields_trn.emp_id) AND (afe.hsaf_id = tblHS_area_fields_trn.hsaf_id))
LEFT JOIN tblEmployees ON (afe.emp_id = tblEmployees.emp_id) AND (afe.hs_area_id = tblEmployees.hs_area_id)) ON tblHS_fields.hsf_id = afe.hsf_id)
INNER JOIN tblHS_area_fields ON afe.hsaf_id = tblHS_area_fields.hsaf_id
WHERE (((tblEmployees.no_hs_rec)=No) AND ((tblEmployees.obsolete)=No) AND ((tblHS_fields.trn)=Yes))
GROUP BY afe.hs_area_id, afe.hsf_id, afe.hsaf_id;
Thanks
Last edited: