SELECT p.name,MIN(tsl.unit_price_before_discount) min_cost,MAX(tsl.unit_price_before_discount) max_cost,AVG(tsl.unit_price_before_discount) avg_cost FROM products p JOIN transaction_sell_lines tsl ON p.id=tsl.product_id JOIN transactions t ON tsl.transaction_id=t.id WHERE t.type="sell" GROUP BY p.id,p.name ORDER BY (max_cost-min_cost)/max_cost DESC;