I have two Queries which work independently; I need to combine these results.
- Fetch all fields (including
wdate
andEmpid
), fromFromdate
toToDate
. - Calculate a value (for efficiency,
Efc
), for a specificwdate
andEmpid
from First Query.
1st Query
SELECT *
FROM tblProductionEffcyDetails
WHERE wDate BETWEEN '06/26/2019' AND '07/25/2019'
AND worker = 'Techn'
ORDER BY Empid, wDate
2nd Query
SELECT Cast(ROUND(SUM(Tstdmin) / NULLIF(SUM(TAvlblmin), 0) * 100,0) as int) AS [Efc]
FROM tblProductionEffcyDetails
WHERE wDate='07/11/2019'
AND Empid='00021'
GROUP BY wdate, Empid
That is, in this 2nd Query, the values for wDate
and Empid
should come from the results of the 1st Query.
Notes on the data/ table:
- Any particular date (
wDate
) or person (Empid
) can have any number of entries. - Efficiency (
Efc
) should be given just once per day (wDate
) i.e. it should not have multiple values for a particularwDate
.
Table structure is as below
SL wDate Avlbl_Mins NP_Mins Empid Name Process Model Efc
117571 7/13/2019 0 0 21 MARRY Block removing 900-2930 80
117572 7/13/2019 0 0 21 MARRY Microscope checking 900-2929 Null
116872 6/26/2019 430 75 52 SUGANTHI Slab removing 900-2929 75
116873 6/26/2019 0 0 52 SUGANTHI Slab Removing 900-2528 Null