SELECT c.name,MIN(t.transaction_date) first_purchase,MAX(t.transaction_date) last_purchase,DATEDIFF(MAX(t.transaction_date),MIN(t.transaction_date)) customer_lifespan FROM contacts c JOIN transactions t ON c.id=t.contact_id WHERE t.type="sell" GROUP BY c.id,c.name HAVING customer_lifespan>0 ORDER BY customer_lifespan DESC;