SQL
All Top 50 SQL Interview Questions#50
Track First and Most Recent Customer Touchpoints with FIRST_VALUE in SQL
HardGoogleInterview Question #50
Asked at GoogleGiven `touchpoints` (customer_id, channel, touched_at), write a SQL query using window functions to display each customer's `customer_id`, original first marketing channel `first_channel`, and most recent marketing channel `last_channel`.
Input Table: touchpoints
3 rows preview| customer_id | channel | touched_at |
|---|---|---|
| 101 | Organic Google | 2026-01-01 10:00:00 |
| 101 | Instagram Ad | 2026-01-15 14:00:00 |
| 101 | Direct Email | 2026-02-01 09:00:00 |
Expected Output Structure1 rows
| customer_id | first_channel | last_channel |
|---|---|---|
| 101 | Organic Google | Direct Email |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.