Comments Under Posts
Comments Under Posts
A social network is building an activity dashboard for its publications. The table stores posts and comments. A post is a row where parent_id IS NULL. Its post_id is its own sub_id. A comment is a row whose parent_id equals the sub_id of its post.
For each post, count the number of unique comments. Return:
- post_id
- number_of_comments
Include posts with no comments with a value of 0. Sort the result by post_id.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.
| post_id | number_of_comments |
|---|---|
| 1 | 3 |
| 2 | 2 |
| 3 | 1 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inFocus radio
Paused · SomaFM · Fluid