Your question is SQL for Weekly Lead KPIs. 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.
Stanley Martin Homes marketing analysts need a weekly view of lead performance across acquisition channels used by the Stanley Martin Homes website and CRM. Write a PostgreSQL query for the period from 2025-01-06 through 2025-02-02.
converted = TRUE, and average cost per lead as weekly spend divided by lead volume.| Column | Type | Description |
|---|---|---|
| channel_idPK | INT | Primary key for a marketing channel |
| channel_name | VARCHAR(80) | Marketing acquisition channel name |
| Column | Type | Description |
|---|---|---|
| lead_idPK | INT | Primary key for a lead |
| channel_id | INT | Marketing channel attributed to the lead |
| created_at | DATE | Date the lead entered the Stanley Martin Homes CRM |
| converted | BOOLEAN | Whether the lead converted |
| Column | Type | Description |
|---|---|---|
| spend_idPK | INT | Primary key for a spend record |
| channel_id | INT | Marketing channel receiving the spend |
| spend_date | DATE | Date the spend was recorded |
| amount | DECIMAL(10,2) | Spend amount for the channel and date |