Your product analytics team wants to understand user engagement breadth — specifically, how many different types of events each user has triggered. Using the events table, return each user_id along with distinct_event_count, the number of distinct event types they triggered. Sort by distinct_event_count descending (most engaged users first), then by user_id ascending to break ties.
events
| column | type |
|---|---|
| id | INTEGER |
| user_id | INTEGER |
| event_type | TEXT |
| created_at | TIMESTAMP |
| id | user_id | event_type | created_at |
|---|---|---|---|
| 1 | 1 | click | 2024-01-01 10:00:00 |
| 2 | 1 | scroll | 2024-01-01 10:01:00 |
| 3 | 1 | click | 2024-01-01 10:02:00 |
| 4 | 2 | click | 2024-01-01 10:03:00 |
| 5 | 2 | purchase | 2024-01-01 10:04:00 |
| 6 | 2 | scroll | 2024-01-01 10:05:00 |
| user_id | distinct_event_count |
|---|---|
| 2 | 3 |
| 1 | 2 |
User 2 triggered three distinct event types (click, purchase, scroll). User 1 triggered two (click, scroll) — the duplicate click is not counted again.