Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19226d6

Browse files
committed
Add a question
1 parent 7b93164 commit 19226d6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

‎README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,3 +1506,54 @@ WHERE store3 IS NOT NULL
15061506
---
15071507

15081508
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**
1509+
1510+
## 45. Find the Team Size
1511+
1512+
Write a SQL query to find the team size of each of the employees. Return result table in any order. Here is an example:
1513+
1514+
```
1515+
Employee Table:
1516+
+-------------+------------+
1517+
| employee_id | team_id |
1518+
+-------------+------------+
1519+
| 1 | 8 |
1520+
| 2 | 8 |
1521+
| 3 | 8 |
1522+
| 4 | 7 |
1523+
| 5 | 9 |
1524+
| 6 | 9 |
1525+
+-------------+------------+
1526+
```
1527+
1528+
```
1529+
Result table:
1530+
+-------------+------------+
1531+
| employee_id | team_size |
1532+
+-------------+------------+
1533+
| 1 | 3 |
1534+
| 2 | 3 |
1535+
| 3 | 3 |
1536+
| 4 | 1 |
1537+
| 5 | 2 |
1538+
| 6 | 2 |
1539+
+-------------+------------+
1540+
```
1541+
1542+
<details><summary>Solution</summary>
1543+
1544+
```sql
1545+
SELECT employee.employee_id, team.team_size
1546+
FROM employee
1547+
LEFT JOIN (
1548+
SELECT team_id, COUNT(employee_id) AS team_size
1549+
FROM employee
1550+
GROUP BY team_id
1551+
) team
1552+
ON employee.team_id = team.team_id;
1553+
```
1554+
1555+
</details>
1556+
1557+
---
1558+
1559+
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /