데이터 분석/SQL 연습문제
New Companies (HackerRank)
중급닌자 연습생
2022. 10. 5. 23:08
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.
풀이
제출한 답
select
c.company_code, c.founder,
(select count(distinct Lead_Manager_code)
from Lead_Manager
where company_code = c.company_code)
,(select count(distinct senior_Manager_code)
from senior_Manager
where company_code = c.company_code)
,(select count(distinct Manager_code)
from Manager
where company_code = c.company_code)
,(select count(distinct employee_code)
from employee
where company_code = c.company_code)
from company as c
order by c.company_code asc
-> select 절 서브쿼리로 구하려는 count 값을 하나씩 구해줌