SELECT p.name,SUM(CASE WHEN t.transaction_date>=DATE_SUB(CURRENT_DATE,INTERVAL 3 MONTH) THEN tsl.quantity ELSE 0 END) as current_sales,SUM(CASE WHEN t.transaction_date BETWEEN DATE_SUB(CURRENT_DATE,INTERVAL 6 MONTH) AND DATE_SUB(CURRENT_DATE,INTERVAL 3 MONTH) THEN tsl.quantity ELSE 0 END) as prev_sales 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 HAVING current_sales>0 ORDER BY ((current_sales-prev_sales)/NULLIF(prev_sales,0)*100) DESC;