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 값을 하나씩 구해줌
'데이터 분석 > SQL 연습문제' 카테고리의 다른 글
Weather Observation Station 5 (HackerRank) (0) | 2022.10.12 |
---|---|
Occupations (HackerRank) (0) | 2022.10.11 |
Contest Leaderboard (HackerRank) (0) | 2022.10.04 |
Weather Observation Station 17 (HackerRank) (0) | 2022.09.29 |
185. Department Top Three Salaries (LeetCode) (0) | 2022.09.26 |
댓글