• + 6 comments

    Solution 1

    This is the solution I came up with for MySQL:

    SELECT c.company_code, c.founder, COUNT(DISTINCT e.lead_manager_code), COUNT(DISTINCT e.senior_manager_code), COUNT(DISTINCT e.manager_code), COUNT(DISTINCT e.employee_code)
    FROM Company AS c
    INNER JOIN Employee AS e
    ON c.company_code = e.company_code
    GROUP BY c.company_code, c.founder
    ORDER BY c.company_code;
    

    This code only uses the two tables 'Company' and 'Employee', instead of using all the 5 tables provided.