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.
I ran into this issue - Wrote a pretty much identical query to his and ran into this problem. Here was my original code:
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,
Lead_Manager L,
Senior_Manager S,
Manager M,
Employee E
WHERE C.Company_Code = L.Company_Code
AND L.Lead_Manager_Code = S.Lead_Manager_Code
AND S.Senior_Manager_Code = M.Senior_Manager_Code
AND M.Manager_Code = E.Manager_Code
GROUP BY C.Company_Code
ORDER BY C.Company_Code;
As you can see all the selected columns are aggregate functions except for the first two. Since we are grouping by Company Code, it reduces the entries for that code to one row so it can match aggregates like COUNT(). But if we're not grouping by Founder, we will still end up with multiple entries since we've only selected Founder.
Let me know if that makes sense. It's just my beginner-level understanding of it.
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 →
I ran into this issue - Wrote a pretty much identical query to his and ran into this problem. Here was my original code:
As you can see all the selected columns are aggregate functions except for the first two. Since we are grouping by Company Code, it reduces the entries for that code to one row so it can match aggregates like COUNT(). But if we're not grouping by Founder, we will still end up with multiple entries since we've only selected Founder.
Let me know if that makes sense. It's just my beginner-level understanding of it.