Table Schema
Inspect
Table
| Column | Type |
|---|---|
| reaction_id | integer |
| post_id | integer |
Find posts with more than 5 reactions.
Table Schema
| Column | Type |
|---|---|
| reaction_id | integer |
| post_id | integer |
Sample Data
| reaction_id | post_id |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
| 7 | 2 |
| 8 | 2 |
| post_id |
|---|
| 1 |
SQL Editor
| post_id |
|---|
| 1 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT post_id FROM reactions GROUP BY post_id HAVING COUNT(*) > 5;
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions