Last updated on January 21st, 2025 at 03:49 am
Here, we see a Find the Team Size LeetCode Solution. This Leetcode problem is solved using MySQL and Pandas.
List of all LeetCode Solution
Level of Question
Easy
Find the Team Size LeetCode Solution
Table of Contents
1. Problem Statement
Column Name | Type |
employee_id | int |
team_id | int |
employee_id is the primary key for this table.
Each row of this table contains the ID of each employee and their respective team.
Write an SQL query to find the team size of each of the employees. Return result table in any order.
The result format is in the following example.
Example 1:
Input:
employee_id | team_id |
1 | 8 |
2 | 8 |
3 | 8 |
4 | 7 |
5 | 9 |
6 | 9 |
Output:
employee_id | team_size |
1 | 3 |
2 | 3 |
3 | 3 |
4 | 1 |
5 | 2 |
6 | 2 |
2. Code Implementation in Different Languages
2.1 Find the Team Size MySQL
select employee_id, team_size from Employee as e join ( select team_id, count(*) as team_size from employee group by team_id ) as t on e.team_id = t.team_id;