You're working as a database analyst for a company that wants to understand team dynamics better. Given an Employee table that maps each employee to their team, your task is to find the team size for each employee.
The Employee table has the following structure:
| Column Name | Type |
|---|---|
| employee_id | int |
| team_id | int |
Where employee_id is the primary key (unique values) and each row contains an employee's ID and their respective team ID.
Goal: Write a SQL query to return each employee along with the size of their team.
Example:
If Team A has 3 members and Team B has 2 members, then every employee in Team A should show team_size = 3, and every employee in Team B should show team_size = 2.
Input & Output
Visualization
Time & Space Complexity
Single scan through the table with efficient partitioning
Output table has same size as input, no additional space for joins
Constraints
- 1 โค employee_id โค 105
- 1 โค team_id โค 105
- employee_id is unique (primary key)
- The result can be returned in any order