Write a query to find the department ids where more than 10 employees are working.Consider employee table has department_id as a foreign key
Question
Write a query to find the department ids where more than 10 employees are working.Consider employee table has department_id as a foreign key
Solution
Sure, here is a SQL query that will return the department IDs where more than 10 employees are working:
SELECT department_id
FROM employee
GROUP BY department_id
HAVING COUNT(*) > 10;
Here's a step-by-step explanation of this query:
-
SELECT department_id: This tells SQL that we want to see the department_id in our results. -
FROM employee: This tells SQL to look in the employee table. -
GROUP BY department_id: This groups the results by department_id. This means that all employees who work in the same department will be grouped together. -
HAVING COUNT(*) > 10: This is a condition that the groups we defined earlier must meet.COUNT(*)counts the number of rows in each group. SoHAVING COUNT(*) > 10means "only show me the groups that have more than 10 rows". In other words, only show me the department_ids where more than 10 employees work.
Similar Questions
Consider the following EmployeeDetails table.You want to display the details of employees whose salary is more than the lowest salary of department having ID 10.To perform this task, which of the following query you can use the
You have two tables employee and department that have 10 records. In the given context, determine the type of join being used in the query given alongside.SELECT employee.emp_id, department.emp_id, name, dept_id FROM employee, department; Inner JoinOuter JoinEqui-JoinCartesian Join
Write a SQL query considering below schema. Create tables with Primary Key, foreign key constraints in given schemas.Manager (mid, eid, mname)Department (did, mid, dname, location)Employee (eid, ename, mobile, salary, joining_date, mid)i.Give the name and salary of employees whose salary are greater than each and every employees who are working under managerid 14.ii.Give the name of employees who have not assigned any department.iii.Give the employee names whose location is Kota.iv.Give the name of manager along with count of employees assigned to him/her in descending order
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
Write a query to display the employee_id and department_id of the employees who works less than 50 percent_time. Display the records sorted in ascending order based on employee_id.
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.