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;
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e9e8-2c40e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e9e8-2c40e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?