1241. Number of Comments per Post

https://leetcode.com/problems/number-of-comments-per-post

Description

Table: Submissions

+---------------+----------+
| Column Name   | Type     |
+---------------+----------+
| sub\_id        | int      |
| parent\_id     | int      |
+---------------+----------+
There is no primary key for this table, it may have duplicate rows.
Each row can be a post or comment on the post.
parent\_id is null for posts.
parent\_id for comments is sub_id for another post in the table.

Write an SQL query to find number of comments per each post.

Result table should contain post_id and its corresponding number_of_comments, and must be sorted by post_idin ascending order.

Submissions may contain duplicate comments. You should count the number of unique comments per post.

Submissions may contain duplicate posts. You should treat them as one post.

The query result format is in the following example:

ac

Last updated

Was this helpful?