SELECT bl.name location,SUM(t.final_total) revenue,SUM((tsl.unit_price_inc_tax-tsl.unit_price_before_discount)*tsl.quantity) gross_profit FROM business_locations bl JOIN transactions t ON bl.id=t.location_id JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id WHERE t.type="sell" GROUP BY bl.id,bl.name ORDER BY gross_profit DESC;