그냥 풀기
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 AS C,
Lead_Manager AS L,
Senior_Manager AS S,
Manager AS M,
Employee AS 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
ORDER BY C.company_code
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 AS C
INNER JOIN Lead_Manager AS L
ON C.company_code = L.company_code
INNER JOIN Senior_Manager AS S
ON L.lead_manager_code = S.lead_manager_code
INNER JOIN Manager AS M
ON S.senior_manager_code = M.senior_manager_code
INNER JOIN Employee AS E
ON M.manager_code = E.manager_code
GROUP BY C.company_code, C.founder
ORDER BY C.company_code
'MYSQL 코테 준비' 카테고리의 다른 글
[HacKerRank SQL] SQL Project Planning - MYSQL (0) | 2021.03.09 |
---|---|
[HacKerRank SQL] Ollivander's Inventory - MYSQL (0) | 2021.02.25 |
[HacKerRank SQL] Top Competitors - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] The Report - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] Asian Population- MYSQL (0) | 2021.02.24 |
댓글