For every conversion, return the first marketing touch by the same user within the 30 days before it. Conversions with no touch in that window still appear, with a null channel and touched_at.
conversion_id, user_id, channel, touched_at — one row per conversion.
converted_at - 30 days <= touched_at <= converted_at, both ends inclusive. A touch after the conversion does not count.touched_at break on channel ascending.conversion_id.touches has up to 200,000,000 rows, so a correlated subquery per conversion will time out.touches| channel | user_id | touched_at |
|---|---|---|
| 42 | 2024-04-03 18:00:00 | |
| search | 42 | 2024-04-01 09:00:00 |
| display | 43 | 2024-01-01 00:00:00 |
conversions| user_id | converted_at | conversion_id |
|---|---|---|
| 42 | 2024-04-10 12:00:00 | 900 |
| 43 | 2024-04-10 12:00:00 | 901 |
| conversion_id | user_id | channel | touched_at |
|---|---|---|---|
| 900 | 42 | search | 2024-04-01 09:00:00 |
| 901 | 43 | null | null |
touches| channel | user_id | touched_at |
|---|---|---|
| display | 1 | 2024-03-01 11:59:59 |
| search | 1 | 2024-03-01 12:00:00 |
| 1 | 2024-03-31 12:00:01 | |
| social | 2 | 2024-03-31 12:00:00 |
conversions| user_id | converted_at | conversion_id |
|---|---|---|
| 1 | 2024-03-31 12:00:00 | 10 |
| 2 | 2024-03-31 12:00:00 | 11 |
| conversion_id | user_id | channel | touched_at |
|---|---|---|---|
| 10 | 1 | search | 2024-03-01 12:00:00 |
| 11 | 2 | social | 2024-03-31 12:00:00 |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.