SELECT c.name as category_name, SUM(p.enable_stock * v.default_purchase_price) as inventory_value 
FROM categories c 
JOIN products p ON c.id = p.category_id 
JOIN variations v ON p.id = v.product_id 
WHERE p.enable_stock = 1 
GROUP BY c.id, c.name 
ORDER BY inventory_value DESC;