Complete the code to select all employees who work in the department with the highest budget.
SELECT * FROM employees WHERE department_id = (SELECT [1] FROM departments ORDER BY budget DESC LIMIT 1);
The subquery selects the id of the department with the highest budget. The main query then selects employees working in that department.
Complete the code to find products priced higher than the average price.
SELECT product_name FROM products WHERE price > (SELECT [1](price) FROM products);The subquery calculates the average price using AVG(price). The main query selects products priced above this average.
Fix the error in the subquery to find customers who placed orders totaling more than the highest order total among orders over $1000.
SELECT customer_id FROM orders WHERE order_total > (SELECT [1] FROM orders WHERE order_total > 1000);
The subquery must return a single value. Using MAX(order_total) returns the highest order total over $1000, which can be compared correctly.
Fill both blanks to select employees who earn more than the average salary in their department.
SELECT employee_name FROM employees e1 WHERE salary > (SELECT [1](salary) FROM employees e2 WHERE e2.department_id = e1.[2]);
The subquery calculates the average salary (AVG(salary)) for the employee's department (department_id), allowing comparison to find employees earning more.
Fill the blanks to create a subquery that lists products with sales greater than the average sales in their category.
SELECT product_name FROM products p1 WHERE sales > (SELECT [1](sales) FROM products p2 WHERE p2.category_id = p1.[2]);
The subquery calculates the average sales (AVG(sales)) for the product's category (category_id).