Marketing wants to know which channel introduced a customer and which one was in front of them when they bought.
One row per conversion_id, with the columns:
conversion_idfirst_channel — the channel of the earliest touchlast_channel — the channel of the latest touchtouch_countOrder touches by touched_at; where two share one, the smaller touch_id is the earlier.
| touch_id | conversion_id | channel | touched_at |
|---|---|---|---|
| 1 | 100 | SEARCH | 2024-01-01T10:00:00Z |
| 2 | 100 | 2024-01-02T10:00:00Z | |
| 3 | 100 | DIRECT | 2024-01-03T10:00:00Z |
| conversion_id | first_channel | last_channel | touch_count |
|---|---|---|---|
| 100 | SEARCH | DIRECT | 3 |
last_value over an ordered window without an explicit frame returns the current row, not the last one. It is right on the final row of each partition and wrong on every other, which is why it usually looks correct.touches| channel | touch_id | touched_at | conversion_id |
|---|---|---|---|
| SEARCH | 1 | 2024-01-01T10:00:00Z | 100 |
| 2 | 2024-01-02T10:00:00Z | 100 | |
| DIRECT | 3 | 2024-01-03T10:00:00Z | 100 |
| conversion_id | first_channel | last_channel | touch_count |
|---|---|---|---|
| 100 | SEARCH | DIRECT | 3 |
touches| channel | touch_id | touched_at | conversion_id |
|---|---|---|---|
| SOCIAL | 1 | 2024-02-01T00:00:00Z | 200 |
| SEARCH | 2 | 2024-02-02T00:00:00Z | 201 |
| SEARCH | 3 | 2024-02-03T00:00:00Z | 201 |
| conversion_id | first_channel | last_channel | touch_count |
|---|---|---|---|
| 200 | SOCIAL | SOCIAL | 1 |
| 201 | SEARCH | SEARCH | 2 |
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.