https://www.hackerrank.com/challenges/the-company/problem?isFullScreen=true
TABLE NAME : Company
TABLE NAME : Lead_Manager
TABLE NAME : Senior_Manager
TABLE NAME : Manager
TABLE NAME : Manager
1) INNER JOIN 연산
각 테이블의 외래키인 COMPANY_CODE를 이용해서 연결한다.
1) GROUP BY:
GROUP BY A.COMPANY_CODE, A.FOUNDER: 회사 코드와 창립자 정보를 기준으로 그룹화하여 각 회사에 대해 집계된 결과를 제공합니다.
SELECT A.COMPANY_CODE, A.FOUNDER,
COUNT(DISTINCT B.LEAD_MANAGER_CODE),
COUNT(DISTINCT C.SENIOR_MANAGER_CODE),
COUNT(DISTINCT D.MANAGER_CODE),
COUNT(DISTINCT E.EMPLOYEE_CODE)
FROM COMPANY A
INNER JOIN LEAD_MANAGER B ON A.COMPANY_CODE = B.COMPANY_CODE
INNER JOIN SENIOR_MANAGER C ON B.COMPANY_CODE = C.COMPANY_CODE
INNER JOIN MANAGER D ON C.COMPANY_CODE = D.COMPANY_CODE
INNER JOIN EMPLOYEE E ON D.COMPANY_CODE = E.COMPANY_CODE
GROUP BY A.COMPANY_CODE, A.FOUNDER