[문제]
[MySQL]
WITH report_employee AS (
SELECT reports_to
, COUNT(DISTINCT employee_id) AS reports_count
, ROUND(AVG(age), 0) AS average_age
FROM Employees
GROUP BY reports_to
HAVING reports_to IS NOT NULL
)
SELECT e.employee_id
, e.name
, re.reports_count
, re.average_age
FROM Employees AS e
LEFT JOIN report_employee AS re ON e.employee_id = re.reports_to
WHERE re.reports_count IS NOT NULL
AND re.average_age IS NOT NULL
ORDER BY employee_id ASC
'SQL > LeetCode' 카테고리의 다른 글
| [LeetCode] 1757. Recyclable and Low Fat Products (0) | 2025.02.21 |
|---|---|
| [LeetCode] 1741. Find Total Time Spent by Each Employee (0) | 2025.02.21 |
| [LeetCode] 1729. Find Followers Count (0) | 2025.02.21 |
| [LeetCode] 1693. Daily Leads and Partners (0) | 2025.02.21 |
| [LeetCode] 1683. Invalid Tweets (0) | 2025.02.21 |
