Create and save this query (call it qryDefectRanking) -- change TableName to
the real name of the table, and change PrimaryKeyFieldName to the real name
of the primary key field in the table:
SELECT T.Part, T.Defect, T.[Sum of Defects],
((SELECT Count(*) FROM TableName AS A
WHERE A.Part = T.Part AND A.Defect = T.Defect
AND A.[Sum of Defects] <= T.[Sum of Defects]) -
(SELECT Count(*) FROM TableName AS B
WHERE B.Part = T.Part AND B.Defect = T.Defect
AND B.[Sum of Defects] = B.[Sum of Defects]
AND B.PrimaryKeyFieldName > T.PrimaryKeyFieldName))
AS DefectRankNumber
FROM TableName AS T;
Create this query to provide the desired data -- change TableName to the
real name of the table:
SELECT T.Part,
(SELECT Q1A.Defect
FROM qryDefectRanking AS Q1A
WHERE Q1A.Part = T.Part AND
Q1A.DefectRankNumber = 1) AS DefectRank1,
(SELECT Q1B.[Sum of Defects]
FROM qryDefectRanking AS Q1B
WHERE Q1B.Part = T.Part AND
Q1B.DefectRankNumber = 1) AS SumOfDefectsRank1,
(SELECT Q2A.Defect
FROM qryDefectRanking AS Q2A
WHERE Q2A.Part = T.Part AND
Q2A.DefectRankNumber = 2) AS DefectRank2,
(SELECT Q2B.[Sum of Defects]
FROM qryDefectRanking AS Q2B
WHERE Q2B.Part = T.Part AND
Q2B.DefectRankNumber = 2) AS SumOfDefectsRank2,
(SELECT Q3A.Defect
FROM qryDefectRanking AS Q3A
WHERE Q3A.Part = T.Part AND
Q3A.DefectRankNumber = 3) AS DefectRank3,
(SELECT Q3B.[Sum of Defects]
FROM qryDefectRanking AS Q3B
WHERE Q3B.Part = T.Part AND
Q3B.DefectRankNumber = 3) AS SumOfDefectsRank3
FROM TableName AS T
ORDER BY T.Part;