Table Schema
Inspect
Table
| Column | Type |
|---|---|
| message_id | integer |
| team_id | varchar |
| user_id | integer |
| sent_date | date |
Find teams with more than 5 messages sent in a day.
Table Schema
| Column | Type |
|---|---|
| message_id | integer |
| team_id | varchar |
| user_id | integer |
| sent_date | date |
Sample Data
| message_id | team_id | user_id | sent_date |
|---|---|---|---|
| 1 | T1 | 101 | 2024-01-01 |
| 2 | T1 | 102 | 2024-01-01 |
| 3 | T1 | 103 | 2024-01-01 |
| 4 | T1 | 104 | 2024-01-01 |
| 5 | T1 | 105 | 2024-01-01 |
| 6 | T1 | 106 | 2024-01-01 |
| 7 | T2 | 101 | 2024-01-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 DISTINCT team_id FROM messages GROUP BY team_id, sent_date 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