Complete the code to select all employees who have a salary greater than the average salary.
SELECT * FROM employees WHERE salary > (SELECT [1] FROM employees);The subquery calculates the average salary using AVG(salary). The main query selects employees earning more than this average.
Complete the code to find products with a price higher than the average price in their category.
SELECT product_name FROM products WHERE price > (SELECT [1] FROM products WHERE category_id = products.category_id);The subquery calculates the average price for the same category using AVG(price). The main query selects products priced above this average.
Fix the error in the query to select customers who placed orders with total amount greater than 1000.
SELECT customer_id FROM orders WHERE order_id IN (SELECT order_id FROM order_details GROUP BY order_id HAVING SUM([1]) > 1000);
The total amount per order is calculated by summing quantity * price in the subquery. Using only quantity or price alone won't give the total order amount.
Fill both blanks to select employees whose salary is higher than the average salary in their department.
SELECT employee_id, salary FROM employees WHERE salary > (SELECT [1] FROM employees WHERE department_id = employees.department_id [2]);
The subquery calculates the average salary with AVG(salary). The condition AND employee_id <> employees.employee_id excludes the current employee to avoid comparing with themselves.
Fill all three blanks to create a query that lists products with price above the average price in their category and stock greater than 50.
SELECT product_name, price, stock FROM products WHERE price > (SELECT [1] FROM products WHERE category_id = products.category_id) AND stock [2] [3];
The subquery uses AVG(price) to find the average price per category. The main query filters products with price greater than this average and stock greater than 50 using stock > 50.