Slack Power Users
Beginner Mode
Objective
Write a SQL query to identify the top two users who sent the most messages in August 2022 on Slack.
Table Schema:
- messages
| Column | Type | Description |
|---|---|---|
| message_id | INTEGER | Unique identifier for each message |
| user_id | INTEGER | ID of the user who sent the message |
| sent_date | DATETIME | Date and time when the message was sent |
Task Requirements:
- Filter only messages sent in August 2022
- Count the total messages sent by each user
- Identify the top two users with the highest message counts
- Return user IDs with their message counts sorted in descending order
Output columns: user_id, message_count
Examples
Example 1:
Output:
Input:
| messages | ||
|---|---|---|
| message_id | sent_date | user_id |
| 1 | 2022-08-01 10:00:00 | 101 |
| 2 | 2022-08-02 11:00:00 | 101 |
| 3 | 2022-08-03 12:00:00 | 101 |
| 4 | 2022-08-05 13:00:00 | 102 |
| 5 | 2022-08-06 14:00:00 | 102 |
| 6 | 2022-08-07 15:00:00 | 103 |
| message_count | user_id |
|---|---|
| 3 | 101 |
| 2 | 102 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Slack