We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
SELECT
C.company_code,
C.founder,
COUNT(DISTINCT LM.lead_manager_code) AS total_lead_managers,
COUNT(DISTINCT SM.senior_manager_code) AS total_senior_managers,
COUNT(DISTINCT M.manager_code) AS total_managers,
COUNT(DISTINCT E.employee_code) AS total_employees
FROM
Company C
LEFT JOIN
Lead_Manager LM ON C.company_code = LM.company_code
LEFT JOIN
Senior_Manager SM ON LM.lead_manager_code = SM.lead_manager_code
LEFT JOIN
Manager M ON SM.senior_manager_code = M.senior_manager_code
LEFT JOIN
Employee E ON M.manager_code = E.manager_code
GROUP BY
C.company_code, C.founder
ORDER BY
C.company_code;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
New Companies
You are viewing a single comment's thread. Return to all comments →
SELECT C.company_code, C.founder, COUNT(DISTINCT LM.lead_manager_code) AS total_lead_managers, COUNT(DISTINCT SM.senior_manager_code) AS total_senior_managers, COUNT(DISTINCT M.manager_code) AS total_managers, COUNT(DISTINCT E.employee_code) AS total_employees FROM Company C LEFT JOIN Lead_Manager LM ON C.company_code = LM.company_code LEFT JOIN Senior_Manager SM ON LM.lead_manager_code = SM.lead_manager_code LEFT JOIN Manager M ON SM.senior_manager_code = M.senior_manager_code LEFT JOIN Employee E ON M.manager_code = E.manager_code GROUP BY C.company_code, C.founder ORDER BY C.company_code;