算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !
今天和大家聊的问题叫做 至少有5名直接下属的经理,我们先来看题面:
https://leetcode-cn.com/problems/managers-with-at-least-5-direct-reports/
解题
法一:自联结
select b.Name
from employee a,employee b
where a.managerId = b.id
group by b.id
having count(*)>=5
法二:子查询
select Name
from employee
where id in
(select distinct managerId
from employee
group by managerId
having count(managerId)>=5)
好了,今天的文章就到这里,如果觉得有所收获,请顺手点个在看或者转发吧,你们的支持是我最大的动力 。
上期推文: