HackerRank SQL: New Compnies

New Companies:

Amber’s conglomerate corporation just acquired some new companies. Each of the companies follows this hierarchy: img

Given the table schemas below, write a query to print the company_code, founder name, total number of lead managers, total number of senior managers, total number of managers, and total number of employees. Order your output by ascending company_code

Oracle

/*join을 안쓰는 방식*/
select c.company_code,c.founder,
    count(distinct l.lead_manager_code),count(distinct s.senior_manager_code), 
    count(distinct m.manager_code), count(distinct e.employee_code)
    from company c, lead_manager l, senior_manager s, manager m ,employee e
    where c.company_code = l.company_code and
          l.lead_manager_code = s.lead_manager_code and
          s.senior_manager_code = m.senior_manager_code and
          m.manager_code = e.manager_code
    group by c.company_code,c.founder
    order by c.company_code;
    /*각 회사와 창립자에 따른 고유한 lead_manager_code,senior_manager_code,manager_code,employee_code를 추출한다*/
    /*회사 코드를 시작으로 각 상위 단계의 code와 매칭을 시켜 회사와 창립자에 따른 고유 개수 추출*/
/*join을 쓰는 방식*/
select c.company_code, 
    c.founder, 
    count(distinct e.lead_manager_code), 
    count(distinct e.senior_manager_code), 
    count(distinct e.manager_code), 
    count(distinct e.employee_code)
from company c
    inner join employee e on e.company_code = c.company_code
group by c.company_code,c.founder
order by c.company_code;