• + 58 comments

    Very nice. I like that you didn't use any joins here, because this section implies that you should use "Advanced Select" technique rather than "Advanced Join" technique. Your solution is working well for MSSQL as well (though there is one more group by needed for selecting c.founder). The version in T-SQL I came up with:

    select c.company_code, c.founder, count(distinct lm.lead_manager_code), 
    count(distinct sm.senior_manager_code), count(distinct m.manager_code), 
    count(distinct e.employee_code)
    
    
    from Company c, Lead_Manager lm, Senior_Manager sm, Manager m, Employee e
    where c.company_code = lm.company_code
    	and lm.lead_manager_code = sm.lead_manager_code
    	and sm.senior_manager_code = m.senior_manager_code
    	and m.manager_code = e.manager_code
    group by c.company_code, c.founder
    order by c.company_code