I am trying to create a query that will output only one line per product, giving Summed totals per product of LF Produced (tblProductionNumbers) and Manhours (tblManHours). The query would then divide LF Produced by Manhours for each product to give the value for "Productivity".
Do I need to create several queries to do this?
Below is the code I have so far, and it does output a single product name per line in the query. I just need to add in the info for ManHours from the tblManhours table so that it is Summed for each product before that sum is divided into LF Produced.
Do I need to create several queries to do this?
Below is the code I have so far, and it does output a single product name per line in the query. I just need to add in the info for ManHours from the tblManhours table so that it is Summed for each product before that sum is divided into LF Produced.
Code:
SELECT tblProductList.[Part Number], g.Sum_Of_LF_Produced AS LFProduced
FROM tblProductList INNER JOIN (SELECT tblProductionNumbers.ProductID,
Sum(tblProductionNumbers.[LF Run]) AS Sum_Of_LF_Run,
Sum(tblProductionNumbers.[LF Produced]) AS Sum_Of_LF_Produced
FROM tblProductionHours
INNER JOIN (tblProductList
INNER JOIN tblProductionNumbers ON tblProductList.ID = tblProductionNumbers.ProductID)
ON tblProductionHours.ID = tblProductionNumbers.TimeID
WHERE ((tblProductionHours.Time In ("END-Days","End-Nights")) AND
(DatePart("ww",[ProductionDate])=DatePart("ww",Date())) AND
(Year([ProductionDate])=Year(Date()))) OR ((DatePart("ww",[ProductionDate])="*"))
GROUP BY tblProductionNumbers.ProductID
) AS g ON tblProductList.ID = g.ProductID
GROUP BY tblProductList.[Part Number], g.Sum_Of_LF_Produced;