Your question is SQL for Last Lead by Date. Start with the requirements and the two 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.
Realtor wants to show each agent's most recent lead generated through Realtor surfaces such as the listing portal, referrals, or email campaigns. Write a PostgreSQL query that returns the latest dated lead for every agent.
generated_at for each agent.lead_id.agent_id.| Column | Type | Description |
|---|---|---|
| agent_idPK | INT | Unique Realtor agent identifier |
| agent_name | VARCHAR(100) | Agent display name |
| market | VARCHAR(80) | Agent's primary real estate market |
| Column | Type | Description |
|---|---|---|
| lead_idPK | INT | Unique lead identifier |
| agent_id | INT | Assigned agent identifier |
| generated_at | TIMESTAMP | Timestamp when the lead was generated |
| source | VARCHAR(40) | Realtor lead acquisition source |
| status | VARCHAR(20) | Current lead status |