Find the Team Size LeetCode Solution

This Leetcode problem Find the Team Size LeetCode Solution is done in SQL.

List of all LeetCode Solution

Find the Team Size LeetCode Solution

Find the Team Size LeetCode Solution

Problem Statement

Column NameType
employee_idint
team_idint
Table: Employee

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
18
28
38
47
59
69
Employee Table:

Output:

employee_idteam_size
13
23
33
41
52
62

Explanation:
Employees with Id 1,2,3 are part of a team with team_id = 8.
Employees with Id 4 is part of a team with team_id = 7.
Employees with Id 5,6 are part of a team with team_id = 9.

Find the Team Size LeetCode Solution 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;Code language: SQL (Structured Query Language) (sql)
Scroll to Top