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.
1.select z.company_code, z.founder, z.lm_count, z.sm_count,z.m_count,count(distinct(employee_code)) as e_code
from Employee as e
join
(select b.company_code, b.founder, b.lm_count, b.sm_count, count(distinct(manager_code)) as m_count
from manager as m
join
(select a.company_code, a.founder, a.lm_count, count(distinct(senior_manager_code)) as sm_count
from
(select c.company_code, c.founder, count(distinct(lm.lead_manager_code)) as lm_count
from company as c
join lead_manager as lm
on c.company_code = lm.company_code
group by c.company_code,c.founder) as a
join senior_manager as sm
on a.company_code = sm.company_code
group by a.company_code, a.founder, a.lm_count) as b
on m.company_code = b.company_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
2 is a much more optimized code and there are no subqueries. Can someone please explain to me the constraints b/w 1 and 2 i.e. how one is constrained in respect to 2?
group by b.company_code, b.founder, b.lm_count, b.sm_count) as z
on z.company_code = e.company_code
group by z.company_code, z.founder, z.lm_count, z.sm_count,z.m_count
order by z.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 →
1.select z.company_code, z.founder, z.lm_count, z.sm_count,z.m_count,count(distinct(employee_code)) as e_code from Employee as e join (select b.company_code, b.founder, b.lm_count, b.sm_count, count(distinct(manager_code)) as m_count from manager as m join (select a.company_code, a.founder, a.lm_count, count(distinct(senior_manager_code)) as sm_count from (select c.company_code, c.founder, count(distinct(lm.lead_manager_code)) as lm_count from company as c join lead_manager as lm on c.company_code = lm.company_code group by c.company_code,c.founder) as a join senior_manager as sm on a.company_code = sm.company_code group by a.company_code, a.founder, a.lm_count) as b on m.company_code = b.company_code
2.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
2 is a much more optimized code and there are no subqueries. Can someone please explain to me the constraints b/w 1 and 2 i.e. how one is constrained in respect to 2?
group by b.company_code, b.founder, b.lm_count, b.sm_count) as z on z.company_code = e.company_code group by z.company_code, z.founder, z.lm_count, z.sm_count,z.m_count order by z.company_code