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 to filter by is 5, so we use 5 without quotes because it is a number.
Complete the code to select all employees whose department_id is in the list of department IDs from the departments table.
SELECT * FROM employees WHERE department_id IN (SELECT [1] FROM departments);The subquery should select department_id from the departments table to match with employees' department_id.
Fix the error in the query to select employees who have a salary greater than the average salary in their department.
SELECT * FROM employees WHERE salary > (SELECT AVG([1]) FROM employees WHERE department_id = employees.department_id);The subquery calculates the average salary, so it must use the salary column.
Fill both blanks to select all products with a price higher than the average price in their category.
SELECT * FROM products WHERE price > (SELECT [1] FROM products WHERE category_id = [2]);
The subquery calculates the average price, so use AVG(price). The category filter uses products.category_id to match the outer query.
Fill all three blanks to select employees whose salary is greater than the average salary in their department and whose department name is 'Sales'.
SELECT * FROM employees WHERE salary > (SELECT AVG([1]) FROM employees WHERE department_id = [2]) AND department_id = (SELECT id FROM departments WHERE name = [3]);
The first blank is the salary column for averaging. The second blank must reference the outer employees table's department_id. The third blank is the string 'Sales' to match the department name.