SQL Interview Questions – Find the Team Size

Spread the love

Problem Description –

Write an SQL query to find the team size of each of the employees.

Return result table in any order.

The query result format is in the following example.

Difficulty Level – Easy

Problem Link – Team Size

Solution –

WITH result as
(   
SELECT
    team_id,
    COUNT(*) as team_size
FROM Employee
GROUP BY 1
)

SELECT
    e.employee_id,
    r.team_size
FROM Employee as e JOIN result as r
ON e.team_id = r.team_id
ORDER BY 1

Rating: 1 out of 5.

Leave a Reply