LeetCode 570: Managers with at Least 5 Direct Reports [SQL]

  Рет қаралды 5,764

Frederik Müller

Frederik Müller

Күн бұрын

Solution and walkthrough of leetcode database problem 570: Managers with at Least 5 Direct Reports. I'm using MySQL but this solution should work in any SQL dialect such as PostgreSQL SQL Server, etc.
Link to the problem: leetcode.com/problems/manager...
Playlists:
LeetCode database SQL problems: • LeetCode Database Prob...
Easy SQL problems: • LeetCode Easy Database...
Medium SQL problems: • LeetCode Medium Databa...
Hard SQL problems: • LeetCode Hard Database...

Пікірлер: 18
@IAMSAHAY
@IAMSAHAY 3 жыл бұрын
Man I respect you for your skills
@raghuramsharma2603
@raghuramsharma2603 2 жыл бұрын
Great explanation thanks mate...here is how i wrote the first time. select distinct e2.name from Employee e1 inner join (select name , id from Employee group by id) e2 on e1.managerId = e2.id group by e2.name having count(e1.id) >= 5
@UmaAndLak
@UmaAndLak 2 жыл бұрын
Here is another answer, with self join that works. select distinct m.name from employee e left outer join employee m on e.managerid = m.id group by e.managerID having count(e.ID) >= 5
@imdeepu7855
@imdeepu7855 Жыл бұрын
select name from employee where employee.manager_id IN (select manager_id from employee e group by manager_id having count(manager_id)>5)
@amydong1361
@amydong1361 3 жыл бұрын
Really Appreciated your videos. It helps me a lot when I prepare for my technical interviews. Just wondering are you planing to have some leetcode database python ones?
@frederikmuller
@frederikmuller 3 жыл бұрын
Database problems are SQL only on LeetCode. Check out StrataScratch for Python problems.
@amydong1361
@amydong1361 3 жыл бұрын
@@frederikmuller Thank you for the quick reply! Will keep watching the videos on your channel. Hope you can provide more Python solutions. Your videos are so logical and easy to understand.
@frederikmuller
@frederikmuller 3 жыл бұрын
@@amydong1361 Thank you so much!
@bhaskarpathak8094
@bhaskarpathak8094 Ай бұрын
Try this also select a.name FROM employee a LEFT join employee b ON a.id = b.managerId HAVING COUNT(a.name) >= 5
@containthis4450
@containthis4450 11 ай бұрын
this question is under joins, should we use a join statement instead of a sub query?
@frederikmuller
@frederikmuller 11 ай бұрын
you could also use a self join with the following condition: a.id = b.manager_id then you would also have to filter on managers that have at least 5 matching employees (5 rows)
@vinayak186f3
@vinayak186f3 2 жыл бұрын
@4:19 I think the solution will work even if we remove the distinct clause.
@frederikmuller
@frederikmuller 2 жыл бұрын
you’re right. with DISTINCT this even works when there are duplicate employee entrees
@echoge7683
@echoge7683 3 жыл бұрын
Really appreciate your video. But why you start jumping some SQL questions?
@frederikmuller
@frederikmuller 3 жыл бұрын
wanted to get some more medium and hard questions
@shalvishrivastava5301
@shalvishrivastava5301 2 жыл бұрын
Hey am I wrong. Shouldn’t it be having count managerid >= 5
@frederikmuller
@frederikmuller 2 жыл бұрын
That would be counting how many managers someone has. Since we‘re trying to find employees per manager, we‘re using count distinct id (employeeid).
@shalvishrivastava5301
@shalvishrivastava5301 2 жыл бұрын
@@frederikmuller I feel so stupid. 🤣 Thank you and hats off to all your work, it helps me and a lot of us immensely. Please keep up the goodwork. 👍
LeetCode 1661: Average Time of Process per Machine [SQL]
8:16
Frederik Müller
Рет қаралды 8 М.
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 113 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 96 МЛН
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 99 МЛН
LeetCode Medium 1934 Interview SQL Question with Detailed Explanation
11:47
Everyday Data Science
Рет қаралды 6 М.
LeetCode 197: Rising Temperature [SQL]
8:20
Frederik Müller
Рет қаралды 16 М.
LeetCode 1280: Students and Examinations - Interview Prep Ep 23
12:36
LeetCode 1204: Last Person to Fit in the Elevator/Bus [SQL]
10:26
Frederik Müller
Рет қаралды 4,3 М.
LeetCode 626: Exchange Seats [SQL]
7:58
Frederik Müller
Рет қаралды 8 М.
LeetCode 620: Not Boring Movies [SQL]
6:07
Frederik Müller
Рет қаралды 3,4 М.
MLV Prasad - LeetCode SQL [ Medium] | 0570 | "Managers with at Least 5 Direct Reports" |
6:35
Data Science University - MLV Prasad
Рет қаралды 784
LeetCode 1251 Interview SQL Question with Detailed Explanation | Practice SQL
17:11
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 113 МЛН