Skip to content

Commit fecc631

Browse files
add 1303
1 parent 422ad4c commit fecc631

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ _If you like this project, please leave me a star._ ★
887887
|1327|[List the Products Ordered in a Period](https://leetcode.com/problems/list-the-products-ordered-in-a-period/)|[Solution](../master/database/_1327.sql) || Easy |
888888
|1322|[Ads Performance](https://leetcode.com/problems/ads-performance/)|[Solution](../master/database/_1322.sql) || Easy |
889889
|1308|[Running Total for Different Genders](https://leetcode.com/problems/running-total-for-different-genders/)|[Solution](../master/database/_1308.sql) || Medium |
890+
|1303|[Find the Team Size](https://leetcode.com/problems/find-the-team-size/)|[Solution](../master/database/_1303.sql) || Easy |
890891
|1294|[Weather Type in Each Country](https://leetcode.com/problems/weather-type-in-each-country/)|[Solution](../master/database/_1294.sql) | | Easy |
891892
|1280|[Students and Examinations](https://leetcode.com/problems/students-and-examinations/)|[Solution](../master/database/_1280.sql) | [:tv:](https://www.youtube.com/watch?v=ThbkV4Fs7iE)| Easy |
892893
|1270|[All People Report to the Given Manager](https://leetcode.com/problems/all-people-report-to-the-given-manager/)|[Solution](../master/database/_1270.sql) || Medium |

database/_1303.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--1303. Find the Team Size
2+
--
3+
--Table: Employee
4+
--
5+
--+---------------+---------+
6+
--| Column Name | Type |
7+
--+---------------+---------+
8+
--| employee_id | int |
9+
--| team_id | int |
10+
--+---------------+---------+
11+
--employee_id is the primary key for this table.
12+
--Each row of this table contains the ID of each employee and their respective team.
13+
--Write an SQL query to find the team size of each of the employees.
14+
--
15+
--Return result table in any order.
16+
--
17+
--The query result format is in the following example:
18+
--
19+
--Employee Table:
20+
--+-------------+------------+
21+
--| employee_id | team_id |
22+
--+-------------+------------+
23+
--| 1 | 8 |
24+
--| 2 | 8 |
25+
--| 3 | 8 |
26+
--| 4 | 7 |
27+
--| 5 | 9 |
28+
--| 6 | 9 |
29+
--+-------------+------------+
30+
--Result table:
31+
--+-------------+------------+
32+
--| employee_id | team_size |
33+
--+-------------+------------+
34+
--| 1 | 3 |
35+
--| 2 | 3 |
36+
--| 3 | 3 |
37+
--| 4 | 1 |
38+
--| 5 | 2 |
39+
--| 6 | 2 |
40+
--+-------------+------------+
41+
--Employees with Id 1,2,3 are part of a team with team_id = 8.
42+
--Employees with Id 4 is part of a team with team_id = 7.
43+
--Employees with Id 5,6 are part of a team with team_id = 9.
44+
45+
--# Write your MySQL query statement below
46+
select employee_id, team_size from Employee e
47+
left join
48+
(
49+
select team_id, count(distinct(employee_id)) as team_size from Employee group by team_id
50+
) as t
51+
on e.team_id = t.team_id;

0 commit comments

Comments
 (0)