SELECT CASE WHEN tsl.line_discount_amount>0 THEN "Promo" ELSE "Regular" END type,COUNT(t.id) transactions,SUM(tsl.quantity) units FROM transactions t JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id WHERE t.type="sell" GROUP BY CASE WHEN tsl.line_discount_amount>0 THEN "Promo" ELSE "Regular" END;