Table Schema
Inspect
Table
| Column | Type |
|---|---|
| team_id | varchar |
| user_id | integer |
| join_date | date |
Find teams that added more than 2 members in a month.
Table Schema
| Column | Type |
|---|---|
| team_id | varchar |
| user_id | integer |
| join_date | date |
Sample Data
| team_id | user_id | join_date |
|---|---|---|
| T1 | 101 | 2024-01-01 |
| T1 | 102 | 2024-01-02 |
| T1 | 103 | 2024-01-03 |
| T2 | 104 | 2024-01-01 |
| T2 | 105 | 2024-02-01 |
| team_id |
|---|
| T1 |
SQL Editor
| team_id |
|---|
| T1 |
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 team_id
FROM team_members
GROUP BY team_id, DATE_TRUNC('month', join_date)
HAVING COUNT(*) > 2;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