From e2e3bccd9edc74965b51c73edc3294dc74cea1ba Mon Sep 17 00:00:00 2001 From: Elvis Otieno <125451537+the1Riddle@users.noreply.github.com> Date: Sun, 19 May 2024 15:23:25 +0300 Subject: [PATCH] Update managers-with-at-least-5-direct-reports.sql --- ...managers-with-at-least-5-direct-reports.sql | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/MySQL/managers-with-at-least-5-direct-reports.sql b/MySQL/managers-with-at-least-5-direct-reports.sql index a4c468d..29800a6 100644 --- a/MySQL/managers-with-at-least-5-direct-reports.sql +++ b/MySQL/managers-with-at-least-5-direct-reports.sql @@ -1,17 +1,9 @@ # Time: O(n) # Space: O(n) -SELECT - Name -FROM - Employee AS t1 INNER JOIN - (SELECT - ManagerId - FROM - Employee - GROUP BY ManagerId - HAVING COUNT(ManagerId) >= 5 - ORDER BY NULL) AS t2 - ON t1.Id = t2.ManagerId -; +SELECT name FROM Employee WHERE id IN ( + SELECT managerId + FROM Employee + GROUP BY managerId + HAVING COUNT(*) >= 5)