SELECT t.sub_type channel,COUNT(t.id) transactions,SUM(t.final_total) revenue,AVG((tsl.unit_price_inc_tax-tsl.unit_price_before_discount)/tsl.unit_price_before_discount)*100 margin FROM transactions t JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id WHERE t.type="sell" GROUP BY t.sub_type ORDER BY margin DESC;