Skip to content

Commit f2e484d

Browse files
committed
Upload 124
1 parent 48f0391 commit f2e484d

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ To make the daily tasks of creating a new file and updating the index easier, th
152152
| 121 | [Find Followers Count](https://leetcode.com/problems/find-followers-count/description/) | [Solution](solutions/121_find_followers_count.md) | LeetCode | Easy | |
153153
| 122 | [Biggest Single Number](https://leetcode.com/problems/biggest-single-number/description/) | [Solution](solutions/122_biggest_single_number.md) | LeetCode | Easy | |
154154
| 123 | [Customers Who Bought All Products](https://leetcode.com/problems/customers-who-bought-all-products/description/) | [Solution](solutions/123_customers_who_bought_all_products.md) | LeetCode | Medium | |
155+
| 124 | [The Number of Employees Which Report to Each Employee](https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee/description/) | [Solution](solutions/124_the_number_of_employees_which_report_to_each_employee.md) | LeetCode | Easy | |
155156

156157
## Author(s)
157158

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SQL Everyday \#124
2+
3+
## The Number of Employees Which Report to Each Employee
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Write a solution to report the ids and the names of all *managers*, the number of employees who report *directly* to them, and the average age of the reports rounded to the nearest integer.
11+
12+
Return the result table ordered by `employee_id`. [[Full Description](https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
SELECT
19+
e1.employee_id
20+
,e1.name
21+
,COUNT(e2.employee_id) AS reports_count
22+
,ROUND(AVG(e2.age)) AS average_age
23+
FROM Employees e1
24+
JOIN Employees e2 ON e1.employee_id = e2.reports_to
25+
WHERE e2.reports_to IS NOT NULL
26+
GROUP BY e1.employee_id
27+
ORDER BY e1.employee_id
28+
;
29+
```
30+
31+
## Site Solution
32+
33+
```sql
34+
-- LeetCode Solution
35+
SELECT
36+
reports_to AS employee_id,
37+
(
38+
SELECT
39+
name
40+
FROM
41+
employees e1
42+
WHERE
43+
e.reports_to = e1.employee_id
44+
) AS name,
45+
COUNT(reports_to) AS reports_count,
46+
ROUND(
47+
AVG(age)
48+
) AS average_age
49+
FROM
50+
employees e
51+
GROUP BY
52+
reports_to
53+
HAVING
54+
reports_count > 0
55+
ORDER BY
56+
employee_id
57+
```
58+
59+
## Notes
60+
61+
TODO
62+
63+
Go to [Table of Contents](/README.md#contents)\
64+
Go to [Overview](/README.md)

0 commit comments

Comments
 (0)