SQL Interview question Black Rock Data Analyst
Company: BlackRock
CTC: 26LPA
Source: Linked Post
Solution:
SELECT manager_id, count(*) as num_emp
FROM employees1
GROUP BY manager_id
ORDER BY num_emp desc
LIMIT 1;
Here, we want to find out the manager who supervises the most employees. To achieve this, the query works in the following steps:
COUNT(*)
to count how many employees each manager supervises.COUNT(*)
counts all rows in the employees
table for each manager_id
, meaning it will count how many employees each manager is overseeing.GROUP BY manager_id
ensures that the data is grouped by each manager. So, for each manager_id
, we will get a count of how many employees report to that manager.ORDER BY num_employees DESC
sorts the result by the number of employees each manager supervises, in descending order. This will put the manager with the highest number of employees at the top of the list.LIMIT 1
ensures that we only get the top result, i.e., the manager who supervises the most employees.ORDER BY
in descending order and limiting the result to just 1, the query ensures we get only the top manager.The query counts how many employees each manager supervises, orders them by the count, and returns the manager with the highest number of employees.
Hi, I am Vishal Jaiswal, I have about a decade of experience of working in MNCs like Genpact, Savista, Ingenious. Currently i am working in EXL as a senior quality analyst. Using my writing skills i want to share the experience i have gained and help as many as i can.
Pivot tables are a powerful tool for summarizing and analyzing data, and Python’s Pandas library…
Welcome to Section 3 of our Data Science Interview Questions series! In this part, we…
Welcome back to our Data Science Interview Questions series! In the first section, we explored…
Data Science Questions in Section 1 focus on the essential concepts of Data Visualization and…
In this article, we’ve compiled 30 carefully selected multiple choice questions (MCQs) with answers to…
Welcome to Day 15 of our Python for Data Science journey!On Day 15, we dived…