Business Context
NewWave Telecom & Technologies uses customer activity events to analyze engagement across its digital services. The Data Analyst team needs a per-user lifecycle summary for the NewWave customer activity dashboard.
Task
Write a PostgreSQL query that returns the first and last valid event for every user in users, including users who have no valid events.
Requirements
- Exclude events whose
event_at is NULL.
- Rank events independently for each user by timestamp, using
event_id as the deterministic tie-breaker.
- Return the first and last event timestamps and event names.
- Return elapsed minutes between the first and last event, or
NULL when no valid event exists.
- Preserve users without events, and label unmatched event types as
Unknown.
- Sort by
user_id.