Practice Interview Questions
| Question | Status |
|---|---|
Write a SQL query to calculate a cumulative distribution showing the total number of users falling into each 'comment frequency' bucket. For instance, the first bucket will include users with 0 comments, the second for users with 1 comment, and so on.
users table:
| Column Name | Description |
|---|---|
| id | Unique identifier for the user |
| name | Name of the user |
| created_at | Account creation time |
| neighborhood_id | The user's neighborhood ID |
| sex | Gender of the user |
comments table:
| Column Name | Description |
|---|---|
| user_id | User ID who made the comment |
| body | Content of the comment |
| created_at | Comment creation time |
| frequency | cum_total |
|---|---|
| 0 | 4 |
| 1 | 5 |
| 2 | 7 |
Write a SQL query to calculate a cumulative distribution showing the total number of users falling into each 'comment frequency' bucket. For instance, the first bucket will include users with 0 comments, the second for users with 1 comment, and so on.
users table:
| Column Name | Description |
|---|---|
| id | Unique identifier for the user |
| name | Name of the user |
| created_at | Account creation time |
| neighborhood_id | The user's neighborhood ID |
| sex | Gender of the user |
comments table:
| Column Name | Description |
|---|---|
| user_id | User ID who made the comment |
| body | Content of the comment |
| created_at | Comment creation time |
| frequency | cum_total |
|---|---|
| 0 | 4 |
| 1 | 5 |
| 2 | 7 |