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.
- Prepare
- SQL
- Advanced Select
- New Companies
- Discussions
New Companies
New Companies
Sort by
recency
|
2614 Discussions
|
Please Login in order to post a comment
SELECT C.COMPANY_CODE, C.FOUNDER, COUNT(DISTINCT L.LEAD_MANAGER_CODE), COUNT(DISTINCT S.SENIOR_MANAGER_CODE), COUNT(DISTINCT M.MANAGER_CODE), COUNT(DISTINCT E.EMPLOYEE_CODE) FROM COMPANY C INNER JOIN LEAD_MANAGER L ON C.COMPANY_CODE=L.COMPANY_CODE INNER JOIN SENIOR_MANAGER S ON L.COMPANY_CODE=S.COMPANY_CODE INNER JOIN MANAGER M ON S.COMPANY_CODE=M.COMPANY_CODE INNER JOIN EMPLOYEE E ON M.COMPANY_CODE=E.COMPANY_CODE GROUP BY C.COMPANY_CODE,C.FOUNDER ORDER BY C.COMPANY_CODE ASC;
Using with clause
MS SQL SERVER :
MS SQL Server
Select Company.company_code,Company.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 Join Lead_Manager As LM on Company.company_code = LM.company_code Join Senior_Manager As SM on LM.company_code=SM.company_code Join Manager As M on M.company_code=LM.company_code Join Employee As E on E.company_code=M.company_code Group By Company.company_code,Company.founder Order BY Company.company_code ASC;