Your question is SQL Top Campaigns by Revenue. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Collaborative Real Estate wants to identify its strongest marketing campaigns in Q1 2025. Write a PostgreSQL query that attributes won deal revenue to campaigns through leads and ranks campaigns within each marketing channel.
| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| campaign_name | VARCHAR(150) | Collaborative Real Estate campaign name |
| channel | VARCHAR(50) | Marketing acquisition channel |
| status | VARCHAR(20) | Current campaign status |
| Column | Type | Description |
|---|---|---|
| lead_idPK | INT | Unique lead identifier |
| campaign_id | INT | Campaign that generated the lead |
| created_at | DATE | Date the lead was created |
| Column | Type | Description |
|---|---|---|
| deal_idPK | INT | Unique deal identifier |
| lead_id | INT | Lead associated with the deal |
| closed_at | DATE | Date the deal closed |
| revenue | NUMERIC(12,2) | Revenue attributed to the deal |
| deal_status | VARCHAR(20) | Deal outcome |