Loading problem...
A social discussion platform stores both posts and comments in a single event table.
Table: submissions
Data semantics:
Task: For every distinct post, return how many unique comments it has.
Counting rules:
Output requirements:
Supported submission environments:
submissions:
| sub_id | parent_id |
|--------|-----------|
| 1 | null |
| 2 | null |
| 1 | null |
| 12 | null |
| 3 | 1 |
| 5 | 2 |
| 3 | 1 |
| 4 | 1 |
| 9 | 1 |
| 10 | 2 |
| 6 | 7 |[
{"post_id":1,"number_of_comments":3},
{"post_id":2,"number_of_comments":2},
{"post_id":12,"number_of_comments":0}
]Posts are {1, 2, 12}. Post 1 has unique comments {3, 4, 9}. Post 2 has unique comments {5, 10}. Comment (6 -> 7) is ignored because post 7 does not exist.
submissions:
| sub_id | parent_id |
|--------|-----------|
| 100 | null |
| 200 | null |
| 301 | 100 |
| 302 | 100 |
| 302 | 100 |
| 401 | 301 |
| 500 | 900 |[
{"post_id":100,"number_of_comments":2},
{"post_id":200,"number_of_comments":0}
]Duplicate comment row (302 -> 100) counts once. Row (401 -> 301) is ignored because 301 is not a post row. Row (500 -> 900) is also ignored because post 900 does not exist.
submissions:
| sub_id | parent_id |
|--------|-----------|
| 50 | null |
| 75 | null |
| 50 | null |
| 800 | 75 |
| 801 | 75 |
| 802 | 75 |
| 802 | 75 |[
{"post_id":50,"number_of_comments":0},
{"post_id":75,"number_of_comments":3}
]Post 50 appears more than once but is treated as one post with zero comments. Post 75 has unique comments {800, 801, 802}.
Constraints