SQL
Lab
Microsoft Microsoft Interview Question 03

Teams
Collaboration
Activity

Find teams with more than 5 messages sent in a day.

Table Schema

Inspect
Table

interactive
ColumnType
message_idinteger
team_idvarchar
user_idinteger
sent_datedate

Sample Data

Input
Output

Sample Input: messages
message_idteam_iduser_idsent_date
1T11012024-01-01
2T11022024-01-01
3T11032024-01-01
4T11042024-01-01
5T11052024-01-01
6T11062024-01-01
7T21012024-01-01
Expected Output
team_id
T1

SQL Editor

Run
Query

postgresql
Waiting for query

team_id
T1

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

Solution

Locked
Answer

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

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving