0

I want to pick the records with the minimum quantity per package_id

I have these data on TableA

package_id  group_id    quantity
1013        2           8
1013        3           6
1091        4           4
1091        2           8
1014        4           4

and I need to end up to this result

package_id  group_id    quantity
1013        3           6
1091        4           4
1014        4           4

I cannot have a simple Min() because it would Group By group_id as well so I will miss the point.

Thank you

PanosPlat
  • 940
  • 1
  • 11
  • 29
  • 1
    select t1.package_id, t1.group_id, t1.quantity from tableA t1 inner join (select package_id, min(quantity) qty from tableA group by quantitiy) t2 on t1.package_id = t2.package_id and t1.quantity = t2.qty; – Cetin Basoz Feb 03 '22 at 12:10
  • Thank you! I am getting an error: Column 'TableA.package_id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. – PanosPlat Feb 03 '22 at 12:25
  • 1
    @PanosPlat, sorrty that group by would be group by package_id. My bad. – Cetin Basoz Feb 03 '22 at 12:34

0 Answers0