SQLSQL
#50

Track First and Most Recent Customer Touchpoints with FIRST_VALUE in SQL

HardGoogle
Interview Question #50
Asked at Google

Given `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_idchanneltouched_at
101Organic Google2026-01-01 10:00:00
101Instagram Ad2026-01-15 14:00:00
101Direct Email2026-02-01 09:00:00
Expected Output Structure1 rows
customer_idfirst_channellast_channel
101Organic GoogleDirect Email
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us