Write a SQL query to find the top-performing marketing campaigns based on customer acquisition cost and lifetime value. Return the three campaigns with at least two acquired customers, ranked by lifetime value divided by customer acquisition cost. Use lifetime value as the average non-null customer lifetime value.
campaign_id, campaign_name, total_spend, acquired_customers, customer_acquisition_cost, lifetime_value, ltv_to_cac_ratioltv_to_cac_ratio descending, then customer_acquisition_cost ascending, then campaign_id ascending| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| campaign_name | VARCHAR(100) | Marketing campaign name |
| channel | VARCHAR(50) | Primary acquisition channel |
| Column | Type | Description |
|---|---|---|
| spend_idPK | INT | Unique spend record identifier |
| campaign_id | INT | Referenced campaign |
| spend_date | DATE | Date of the spend |
| spend_amount | NUMERIC(12,2) | Amount spent on the campaign |
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| campaign_id | INT | Campaign that acquired the customer |
| acquired_at | DATE | Customer acquisition date |
| lifetime_value | NUMERIC(12,2) | Customer lifetime value |