campaign_touches has one row per marketing touch (user_id, touch_date); a user can be touched several times on the same day. For every user in the table, report the length in days of their longest run of consecutive calendar days with at least one touch (a user touched on isolated days has a longest streak of 1). Output columns: user_id, longest_streak. Order by user_id ascending.
| Column | Type |
|---|---|
| user_id | INTEGER |
| touch_date | DATE |
| user_id | touch_date |
|---|---|
| 1 | 2026-01-01 |
| 1 | 2026-01-02 |
| 1 | 2026-01-03 |
| 1 | 2026-01-05 |
| 2 | 2026-01-01 |
| 2 | 2026-01-03 |
| user_id | longest_streak |
|---|---|
| 1 | 3 |
| 2 | 1 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Consecutive Compliance Filings · Three-Ingredient Meal Bundles ›
{{ 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.