Each user converts at most once. A touch is eligible for a conversion when touch_ts is at or before conv_ts and no more than 30 days earlier (touch_ts >= conv_ts minus 30 days). First-touch gives the full revenue to the earliest eligible touch, last-touch to the latest eligible touch; when timestamps tie, the smaller touch_id is earlier. Conversions with no eligible touch are unattributed. For every channel that has at least one eligible touch, return channel, first_touch_revenue and last_touch_revenue (ROUND to 2, 0 if none). Order by channel.
| Column | Type |
|---|---|
| touch_id | INTEGER |
| user_id | INTEGER |
| channel | TEXT |
| touch_ts | TIMESTAMP |
| touch_id | user_id | channel | touch_ts |
|---|---|---|---|
| 1 | 1 | search | 2026-04-01 10:00:00 |
| 2 | 1 | display | 2026-04-03 12:00:00 |
| 3 | 1 | 2026-04-05 09:00:00 | |
| 4 | 2 | social | 2026-04-02 08:00:00 |
| 5 | 2 | search | 2026-04-02 09:00:00 |
| 6 | 3 | 2026-04-04 10:00:00 | |
| 7 | 4 | display | 2026-04-06 10:00:00 |
| 8 | 5 | social | 2026-04-07 09:00:00 |
| Column | Type |
|---|---|
| user_id | INTEGER |
| conv_ts | TIMESTAMP |
| revenue | REAL |
| user_id | conv_ts | revenue |
|---|---|---|
| 1 | 2026-04-05 10:00:00 | 1200 |
| 2 | 2026-04-02 10:00:00 | 300 |
| 3 | 2026-04-04 18:00:00 | 500 |
| 5 | 2026-04-07 10:00:00 | 150 |
| 6 | 2026-04-08 12:00:00 | 80 |
| channel | first_touch_revenue | last_touch_revenue |
|---|---|---|
| display | 0 | 0 |
| 500 | 1700 | |
| search | 1350 | 300 |
| social | 300 | 150 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Overlapping Licence Subscriptions · First Day Below Reorder Point ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.