Could you tell me how to write this sql?

now goods item Table structure
item_id, title, product_id, type, price

there are multiple commodities under one product, and there are 4 kinds of type for merchandise item. There can be multiple commodities with the same type and the same product_id under the same type.

now there are N merchandise id,. I want to get the product_id, of these goods according to the id, of these goods, and then get the list of items with the lowest price under the combination of all product_id and four type values in the item table according to these product_id.

how to write sql?

Mar.29,2021

select aa.* 
from item aa 
join (
    select a.product_id,a.type,min(a.price) price 
    from item a 
    join (select product_id from item where item_id in (N) ) b
    on a.product_id=b.product_id
    group by product_id,type) bb
on aa.product_id=bb.product_id and aa.type=bb.type and aa.price=bb.price;
Menu