Struggling with MIN function. Need to grab other values on the row with the minimum value. Said differently, I have a parent item, a child item, and a qty. I need for a parent item, the child item and the child item's qty.
Parent Child Value
A AB 1
A BC 2
A CD 3
B AB 4
B BC 5
B EE 6
C AB 2
C EE 4
The query should return as result
Parent Child Value
A AB 1
B AB 4
C EE 4
It is OK that AB is duplicated (because it is unique to parent). My 'group by' did not work, and I suspect I need to use the over by clause with possibly, partition by...
The SQL below does not work 100%. I think the Min_Qty is correct, but the Child is random, not the child affiliated with the Qty and get too many row results.
SELECT Parent,
Child,
MIN(Qty) OVER (PARTITION BY Child) AS Min_Qty
FROM #Temp
GROUP BY Parent, Child, Qty