SELECT c.name,COUNT(t.id) total_purchases,SUM(t.final_total) total_spent,COUNT(DISTINCT p.category_id) categories_explored,DATEDIFF(MAX(t.transaction_date),MIN(t.transaction_date)) customer_tenure FROM contacts c JOIN transactions t ON c.id=t.contact_id JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id JOIN products p ON tsl.product_id=p.id WHERE t.type="sell" GROUP BY c.id,c.name ORDER BY total_spent DESC;