Complete the code to filter rows where the age is greater than 30.
SELECT * FROM employees WHERE age [1] 30;
The WHERE clause filters rows before grouping. Here, we want employees older than 30, so we use age > 30.
Complete the code to show departments having more than 5 employees.
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) [1] 5;
The HAVING clause filters groups after aggregation. We want departments with more than 5 employees, so we use COUNT(*) > 5.
Fix the error in the query to filter employees with salary above 50000 after grouping by department.
SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) [1] 50000;
The WHERE clause cannot filter aggregated results. Use HAVING to filter groups after aggregation.
Fill both blanks to filter products with price greater than 100 and groups having total quantity sold more than 50.
SELECT product_id, SUM(quantity) FROM sales WHERE price [1] 100 GROUP BY product_id HAVING SUM(quantity) [2] 50;
WHERE filters rows before grouping (price > 100). HAVING filters groups after aggregation (SUM(quantity) > 50).
Fill all three blanks to select customers with age over 25, group by city, and only show cities with more than 10 customers.
SELECT city, COUNT(*) FROM customers WHERE age [1] 25 GROUP BY [2] HAVING COUNT(*) [3] 10;
Use WHERE age > 25 to filter customers before grouping. Group by city. Use HAVING COUNT(*) > 10 to filter cities with more than 10 customers.