Perform RFM (Recency, Frequency, Monetary) analysis. For each customer, compute: Recency = days since their last order (from '2025-01-01'), Frequency = number of orders, Monetary = total spend. Then assign each metric a score 1-3 using NTILE(3). Return customer_id, recency_days, frequency, monetary, and their three scores. Sort by monetary descending.
Schema
🔑idINT
🔗customer_idINT
order_dateTEXT
statusTEXT
total_amountREAL
postgresql
Run your query to see results
Press Ctrl + Enter to execute