Question 7Consider two tables: dept_manager and departmentsWrite a query that returns how many managers belong to different departments. (Select all that apply)
Question
Question 7Consider two tables: dept_manager and departmentsWrite a query that returns how many managers belong to different departments. (Select all that apply)
Solution
To answer this question, you would need to write a SQL query that joins the two tables on their common column (presumably department_id or similar), and then counts the distinct number of managers in each department. Here's how you could do it:
SELECT d.dept_name, COUNT(DISTINCT dm.manager_id) as num_managers
FROM dept_manager dm
JOIN departments d ON dm.dept_id = d.dept_id
GROUP BY d.dept_name;
This query works as follows:
-
SELECT d.dept_name, COUNT(DISTINCT dm.manager_id) as num_managers: This line is selecting the department name from the departments table, and the count of distinct manager IDs from the dept_manager table. TheDISTINCTkeyword ensures that if a manager appears more than once in a department, they are only counted once. -
FROM dept_manager dm JOIN departments d ON dm.dept_id = d.dept_id: This line is joining the dept_manager table (aliased as dm) with the departments table (aliased as d) on the dept_id column, which is presumably a common column in both tables. -
GROUP BY d.dept_name: This line is grouping the results by department name, so that the count of managers is calculated for each department separately.
Please note that the exact column names and table names might vary based on your database schema. You would need to replace dept_id, dept_name, manager_id, dept_manager, and departments with the actual names in your database.
Similar Questions
Find the following table EmployeeDetails, with the attributes EmployeeID, EmpName, Designation, Salary, DeptNo. You are assigned to a task of providing the solution to the operations department by writing the query which displays the employeeID and the Designation of all the employees whose Salaries are more than the Salary of employees designated as ManagerC
Question 2A DEPARTMENTS table contains DEP_NAME, and DEPT_ID_DEP columns and an EMPLOYEES table contains columns called F_NAME and DEP_ID. We want to retrieve the Department Name for each Employee. Which of the following queries will correctly accomplish this?1 pointSELECT D.F_NAME, E.DEP_NAME FROM EMPLOYEES E, DEPARTMENTS D WHERE D.DEPT_ID_DEP = E.DEP_IDSELECT F_NAME, DEP_NAME FROM EMPLOYEES E, DEPARTMENTS D WHERE E.DEPT_ID_DEP = D.DEP_IDSELECT F_NAME, DEP_NAME FROM EMPLOYEES, DEPARTMENTS WHERE DEPT_ID_DEP = DEP_IDSELECT E.F_NAME, D.DEP_NAME FROM EMPLOYEES, DEPARTMENTS
we have following relationsEMP(empno, ename, jobtitle, manager, hiredate, salary, deptno)DEPT(deptno, dname,location)Answer the following queries .1) Find the Employees who get salary more than Chris salary.2) Display department number along with the number of employees which belongs to thatdepartment number
From the given table "dept_det" which has columns as "dept_id", "name1", "manger_id", and "location_id". Write a query to retrieve the manager ID of the department where the department ID is 30.Table name:dept_det
Select all that applyWhich three managers would be classified as middle management?Multiple select question.general managerssupervisorsdivision managersplant managers
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.