User Activity Distribution
Beginner Mode
Objective
Write a SQL query to create a histogram of user posting activity for 2024.
Table Schema:
user_posts
| Column | Type | Description |
|---|---|---|
| post_id | INTEGER | Unique identifier for each post |
| user_id | INTEGER | ID of the user who created the post |
| post_date | DATETIME | Date and time when the post was created |
Task Requirements:
- Filter only posts created in the year 2024
- Count posts per user, then count users per post count
- Sort by post count in ascending order
Output columns: post_bucket, users_num
Examples
Example 1:
Output:
Input:
| user_posts | ||
|---|---|---|
| post_date | post_id | user_id |
| 2024-01-15 10:00:00 | 1 | 101 |
| 2024-02-20 11:00:00 | 2 | 101 |
| 2024-03-10 12:00:00 | 3 | 102 |
| 2024-04-05 13:00:00 | 4 | 103 |
| 2024-05-12 14:00:00 | 5 | 103 |
| 2024-06-18 15:00:00 | 6 | 104 |
| post_bucket | users_num |
|---|---|
| 1 | 2 |
| 2 | 2 |
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 →
Meta