SELECT
TOP 1 PART_NBR
,MINOR_MODEL_NBR
,QTY
,COUNT(QTY)
FROM myTable
WHERE MINOR_MODEL_NBR = '8' AND PART_NBR IN ('PN101', 'PN102', 'PN103')
GROUP BY PART_NBR, MINOR_MODEL_NBR, QTY
ORDER BY MostFrequentQTY DESC;
==============================
The code works for one PART_NBR, but have the following issues:
-
returns only top value for PN101 if I don't have other PART_NBR in the WHERE clause. I have thousands of the PART_NBR, one at a time would be too painful.
-
say there are 3 MINOR_MODEL_NBR, '8', '9, '10'. Each PART_NBR has is own QTY for its perspective MINOR_MODEL_NBR.
-
Desired output:
PART_NBR | MINOR_MODEL_NBR | MostFrequentQTY (currently using the Count function with DESC to get this) -
Ideally, I would just paste a large list of PART_NBR and get only the desired output described in (3) above
Appreciate all the help with this slow thinker...