SELECT p.name,COUNT(t.id) current_sales,LAG(COUNT(t.id)) OVER (PARTITION BY p.id ORDER BY DATE_FORMAT(t.transaction_date,"%Y-%m")) previous_sales,(COUNT(t.id)-LAG(COUNT(t.id)) OVER (PARTITION BY p.id ORDER BY DATE_FORMAT(t.transaction_date,"%Y-%m")))*100.0/NULLIF(LAG(COUNT(t.id)) OVER (PARTITION BY p.id ORDER BY DATE_FORMAT(t.transaction_date,"%Y-%m")),0) growth_rate FROM products p JOIN transaction_sell_lines tsl ON p.id=tsl.product_id JOIN transactions t ON tsl.transaction_id=t.id WHERE t.type="sell" GROUP BY p.id,p.name,DATE_FORMAT(t.transaction_date,"%Y-%m") ORDER BY growth_rate DESC;