Your question is Top 3 Longest Sessions Per User. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Anduril operators use Lattice to monitor and coordinate activity across operational surfaces. The analytics team wants to identify the longest sessions for each user.
Write a PostgreSQL query that returns the top three completed sessions for every user, ranked by session duration.
started_at and ended_at.session_id.NULL ended_at value and users without completed sessions.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique user identifier |
| user_name | VARCHAR(100) | Operator display name |
| Column | Type | Description |
|---|---|---|
| session_idPK | INTEGER | Unique session identifier |
| user_id | INTEGER | References users.user_id |
| started_at | TIMESTAMPTZ | Session start timestamp |
| ended_at | TIMESTAMPTZ | Session end timestamp, or NULL while active |
| surface | VARCHAR(80) | Lattice surface used during the session |