SELECT 
    c.name as customer_name,
    MAX(t.transaction_date) as last_purchase_date,
    DATEDIFF(CURRENT_DATE, MAX(t.transaction_date)) as days_since_last_purchase,
    COUNT(t.id) as total_purchases,
    SUM(t.final_total) as total_spent
FROM contacts c
LEFT JOIN transactions t ON c.id = t.contact_id
WHERE t.type = "sell" AND t.status = "final"
GROUP BY c.id, c.name
HAVING days_since_last_purchase > 90
ORDER BY days_since_last_purchase DESC;