Complete the code to select all employees who work in the department with ID 5.
SELECT * FROM employees WHERE department_id = [1];The department ID 5 is used to filter employees working in that department.
Complete the code to select employees who work in the department named 'Sales'.
SELECT * FROM employees WHERE department_id = (SELECT [1] FROM departments WHERE name = 'Sales');
The subquery selects the department's ID where the name is 'Sales'. This ID is used to find employees in that department.
Fix the error in the query to find employees with salary greater than the average salary.
SELECT * FROM employees WHERE salary > (SELECT [1] FROM employees);The subquery must calculate the average salary using AVG(salary) to compare each employee's salary against it.
Fill both blanks to select employees who have the highest salary in their department.
SELECT * FROM employees e WHERE salary = (SELECT [1] FROM employees WHERE department_id = e.[2]);
The subquery finds the maximum salary in the employee's department. The outer query compares each employee's salary to that maximum.
Fill all three blanks to select departments with more than 10 employees.
SELECT name FROM departments WHERE id IN (SELECT [1] FROM employees GROUP BY [2] HAVING COUNT([3]) > 10);
The subquery groups employees by department_id and counts all employees (*) in each group. Departments with more than 10 employees are selected.