Task
You are given signup data and user activity from an Asana-style product. Write a SQL query to return the first meaningful action each user took after signup. Treat an action as meaningful only when is_meaningful = true, and only consider events that happened at or after the user's signup_at timestamp. If a user has no meaningful post-signup action, they should still appear in the output with NULL action fields.
Return one row per user with the user id, email, signup timestamp, first meaningful event timestamp, action name, and surface name. If multiple qualifying events share the same timestamp for a user, break ties by the smaller event_id.
Schema
users
| column | type | description |
|---|
| user_id | INT | Unique user identifier |
| email | VARCHAR(255) | User email |
| signup_at | TIMESTAMP | Signup timestamp |
| workspace_id | INT | Workspace tied to signup |
| | |
event_types
| column | type | description |
|---|
| event_type_id | INT | Unique event type identifier |
| action_name | VARCHAR(100) | Product action name |
| surface_name | VARCHAR(100) | Asana surface where the action happened |
| is_meaningful | BOOLEAN | Whether the event counts as meaningful activation |
| | |
user_events
| column | type | description |
|---|
| event_id | INT | Unique event identifier |
| user_id | INT | User who triggered the event |
| event_type_id | INT | Event type |
| event_at | TIMESTAMP | Event timestamp |
| metadata | TEXT | Optional event metadata |
Sample data
users
user_events
| event_id | user_id | event_type_id | event_at |
|---|
| 1001 | 101 | 1 | 2024-01-01 09:05:00 |
| 1002 | 101 | 3 | 2024-01-01 09:10:00 |
| 1005 | 102 | 4 | 2024-01-01 09:35:00 |
Expected output
| user_id | email | signup_at | first_meaningful_event_at | action_name | surface_name |
|---|
| 101 | ava@acme.com | 2024-01-01 09:00:00 | 2024-01-01 09:10:00 | create_project | web_app |
| 102 | ben@acme.com | 2024-01-01 09:30:00 | 2024-01-01 09:35:00 | invite_teammate | onboarding_flow |
| 103 | chloe@acme.com | 2024-01-02 10:00:00 | NULL | NULL | NULL |