SELECT p.name,SUM(CASE WHEN tsl.line_discount_amount>0 THEN tsl.quantity ELSE 0 END) promo_units,SUM(CASE WHEN tsl.line_discount_amount=0 THEN tsl.quantity ELSE 0 END) regular_units 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 promo_units DESC;