SELECT bl.name location,COUNT(DISTINCT pr.rack) rack_count,COUNT(t.id) transactions,SUM(t.final_total) revenue FROM business_locations bl JOIN transactions t ON bl.id=t.location_id LEFT JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id LEFT JOIN products p ON tsl.product_id=p.id LEFT JOIN product_racks pr ON p.id=pr.product_id WHERE t.type="sell" GROUP BY bl.id,bl.name ORDER BY revenue DESC;