SELECT 
    p.name as product_name,
    SUM(CASE 
        WHEN t.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH)
        THEN tsl.quantity 
        ELSE 0 
    END) as current_quarter_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 previous_quarter_sales,
    ((SUM(CASE 
        WHEN t.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH)
        THEN tsl.quantity 
        ELSE 0 
    END) - 
    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)) / 
    NULLIF(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), 0) * 100) as growth_percentage
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" 
AND t.status = "final"
AND t.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)
GROUP BY p.id, p.name
HAVING current_quarter_sales > 0 OR previous_quarter_sales > 0
ORDER BY growth_percentage DESC;