• + 0 comments

    Guys this is the simplest query by using last table which is having entire data except founders. Hope you find it useful.

    SELECT E.company_code, C.founder, E.total_LM, E.total_SM, E.total_MC, E.total_EC FROM ( SELECT company_code, COUNT(DISTINCT lead_manager_code) AS total_LM, COUNT(DISTINCT senior_manager_code) AS total_SM, COUNT(DISTINCT manager_code) AS total_MC, COUNT(DISTINCT employee_code) AS total_EC FROM Employee GROUP BY company_code ) AS E JOIN Company AS C ON E.company_code = C.company_code ORDER BY E.company_code;