SELECT pp.product_id, pd.dosage, MAX(pp.num) AS max_num, MIN(pp.num) AS min_num, MIN(pp.price) as min_price, MAX(pp.price) as max_price
FROM product_dosage pd
JOIN product_packaging pp ON pd.product_id = pp.product_id AND pd.dosage = pp.dosage
WHERE pp.is_showed =1AND pp.price !=0GROUPBY pp.product_id, pd.dosage
ORDERBY pp.product_id;
SELECT pp.product_id, pd.dosage, MAX(pp.num) AS max_num, MIN(pp.num) AS min_num, MIN(pp.price) as min_price, MAX(pp.price) as max_price
FROM product_dosage pd
JOIN product_packaging pp ON pd.product_id = pp.product_id AND pd.dosage = pp.dosage
WHERE pp.is_showed =1AND pp.price !=0GROUPBY pp.product_id, pd.dosage
ORDERBY pp.product_id;