I have a table with lots of parts with different quantities and their costs. I have created a query that extracts rows that have a qty nearest a target qty of 10:
The problem is that if their is a part with a qty of 5 and the same part with a qty of 15 then both are displayed, and I am trying to achieve a unique entry for each part.
If I have an assumption that if two of the same parts with an upper and lower qty exist the upper qty should be used, how do I implement this?
Can I ammend the query, or do I need another query on the results of the above query?
Every bit of help is another step on my access education process!
Code:
SELECT A.PartNo, A.Qty,A.Cost
FROM TableName AS A INNER JOIN
(SELECT PartNo, Min(Abs(Qty - 10)) AS MinDiff FROM TableName GROUP BY PartNo)
AS M ON A.PartNo = M.PartNo
WHERE Abs(A.Qty-10) = M.MinDiff;
If I have an assumption that if two of the same parts with an upper and lower qty exist the upper qty should be used, how do I implement this?
Can I ammend the query, or do I need another query on the results of the above query?
Every bit of help is another step on my access education process!