Loading the editor…
Map each lead status onto the bucket sales uses.
The CRM stores new, qualified, customer, and disqualified. The sales standup says Open, Working, Won, and Lost.
Return id, email, and bucket. new becomes Open, qualified becomes Working, customer becomes Won, and disqualified becomes Lost. Sort by created_at, then id.
| id | name | channel | spend | started_on |
|---|---|---|---|---|
| 1 | Spring Search | paid_search | 4200 | 2025-03-01 |
| 2 | Lifecycle Email | 800 | 2025-03-01 | |
| 3 | Podcast Tour | podcast | 2500 | 2025-04-01 |
| id | campaign_id | status | created_at | |
|---|---|---|---|---|
| 1 | 1 | ada@example.com | new | 2025-03-05 |
| 2 | 1 | ada@example.com | qualified | 2025-03-08 |
| 3 | 2 | lin@example.com | new | 2025-03-11 |
Ctrl or Cmd + Enter runs the query. The database resets on every run.
Run the query to see rows from the sample database.
Next exercise: Open payables by vendor
Related: Leads still marked new, Duplicate lead emails