• + 0 comments

    Easy Readable Solution

    WITH CTE AS (SELECT 
    company_code,
    COUNT(DISTINCT(lead_manager_code)) as lm,
    COUNT(DISTINCT(senior_manager_code)) as sm,
    COUNT(DISTINCT(manager_code)) as m,
    COUNT(DISTINCT(employee_code)) as e
    from Employee
    group by company_code)
    select
    CTE.company_code,
    founder,
    lm,
    sm,
    m,
    e
    from CTE
    JOIN Company ON CTE.company_code = Company.company_code;