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.
Why you are using all four tables..We can get data by using only two tabbles Company and Employee..Please correct me if I am wrong...
My solution for Oracle :
/*
Enter your query here.
Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error.
*/
SELECT
company_code,
founder,COUNT_EC,COUNT_MC,COUNT_SMC,COUNT_LMC
FROM
(
SELECT
company_code,
founder,
COUNT(DISTINCT(employee_code)) OVER (PARTITION BY founder) AS COUNT_EC,
COUNT(DISTINCT(manager_code)) OVER (PARTITION BY founder)AS COUNT_MC,
COUNT(DISTINCT(senior_manager_code)) OVER (PARTITION BY founder)AS COUNT_SMC,
COUNT(DISTINCT(lead_manager_code)) OVER (PARTITION BY founder)AS COUNT_LMC
FROM(
SELECT employee_code,manager_code,senior_manager_code,
lead_manager_code,Employee.company_code AS company_code ,Company.founder AS founder
FROM
EMPLOYEE JOIN Company
ON(Employee.company_code=Company.company_code)))
GROUP BY
company_code,
founder,COUNT_EC,COUNT_MC,COUNT_SMC,COUNT_LMC
ORDER BY company_code;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
New Companies
You are viewing a single comment's thread. Return to all comments →
Why you are using all four tables..We can get data by using only two tabbles Company and Employee..Please correct me if I am wrong... My solution for Oracle : /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ SELECT company_code, founder,COUNT_EC,COUNT_MC,COUNT_SMC,COUNT_LMC FROM ( SELECT company_code, founder, COUNT(DISTINCT(employee_code)) OVER (PARTITION BY founder) AS COUNT_EC, COUNT(DISTINCT(manager_code)) OVER (PARTITION BY founder)AS COUNT_MC, COUNT(DISTINCT(senior_manager_code)) OVER (PARTITION BY founder)AS COUNT_SMC, COUNT(DISTINCT(lead_manager_code)) OVER (PARTITION BY founder)AS COUNT_LMC FROM( SELECT employee_code,manager_code,senior_manager_code, lead_manager_code,Employee.company_code AS company_code ,Company.founder AS founder FROM EMPLOYEE JOIN Company ON(Employee.company_code=Company.company_code))) GROUP BY company_code, founder,COUNT_EC,COUNT_MC,COUNT_SMC,COUNT_LMC ORDER BY company_code;