SELECT p.name,AVG(CASE WHEN tsl.quantity>5 THEN tsl.unit_price_before_discount END) bulk_price,AVG(CASE WHEN tsl.quantity<=5 THEN tsl.unit_price_before_discount END) regular_price 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 HAVING bulk_price IS NOT NULL AND regular_price IS NOT NULL ORDER BY (regular_price-bulk_price)/regular_price DESC;