-
[MySQL] 여러 개의 서브 쿼리를 이용하기SQL 2021. 8. 24. 15:39
https://www.hackerrank.com/challenges/the-company/problem
조인을 이용한 풀이는 나중에 해볼 것
select C.company_code, C.founder, (select count(distinct LM.lead_manager_code) from Lead_Manager as LM where LM.company_code = C.company_code), (select count(distinct SM.senior_manager_code) from Senior_Manager as SM where SM.company_code = C.company_code), (select count(distinct M.manager_code) from Manager as M where M.company_code = C.company_code), (select count(distinct E.employee_code) from Employee as E where E.company_code = C.company_code) from Company as C order by C.company_code;
'SQL' 카테고리의 다른 글
[MySQL] SELECT INTO를 이용해 조회 결과를 변수에 저장 (0) 2021.08.29 [MySQL] REPLACE 함수 (0) 2021.08.24 [MySQL] IF 함수를 이용한 BST SELECT (0) 2021.08.23 [MySQL] CONCAT, LOWER, UPPER 함수 (0) 2021.08.23 [MySQL] CASE WHEN ~ THEN ~ END로 pivot table 변환 (0) 2021.08.22