SELECT bl.name location,c.name category,COUNT(t.id) transactions,SUM(tsl.quantity) units,SUM(t.final_total) revenue FROM business_locations bl JOIN transactions t ON bl.id=t.location_id JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id JOIN products p ON tsl.product_id=p.id JOIN categories c ON p.category_id=c.id WHERE t.type="sell" GROUP BY bl.id,bl.name,c.id,c.name ORDER BY revenue DESC;