SELECT 
    c.name as category_name,
    DATE_FORMAT(t.transaction_date, "%Y-%m") as month,
    SUM(tsl.quantity) as total_quantity,
    SUM(tsl.unit_price * tsl.quantity) as total_revenue,
    (SUM(tsl.unit_price * tsl.quantity) - LAG(SUM(tsl.unit_price * tsl.quantity)) OVER 
        (PARTITION BY c.id ORDER BY DATE_FORMAT(t.transaction_date, "%Y-%m"))) as revenue_growth
FROM categories c
JOIN products p ON c.id = p.category_id
JOIN transaction_sell_lines tsl ON p.id = tsl.product_id
JOIN transactions t ON tsl.transaction_id = t.id
WHERE t.type = "sell" AND t.status = "final"
GROUP BY c.id, c.name, DATE_FORMAT(t.transaction_date, "%Y-%m")
ORDER BY c.name, month;