Complete the code to select departments having more than 5 employees.
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) [1] 5;
The HAVING clause filters groups. Here, it selects departments with more than 5 employees, so we use >.
Complete the code to find products with total sales equal to 100 or more.
SELECT product_id, SUM(quantity) FROM sales GROUP BY product_id HAVING SUM(quantity) [1] 100;
We want products with total sales at least 100, so we use >= in HAVING.
Fix the error in the code to correctly filter groups with average score above 80.
SELECT class, AVG(score) FROM results GROUP BY class HAVING AVG(score) [1] 80;
The HAVING clause filters groups with average score greater than 80, so > is correct.
Fill both blanks to select customers with total orders more than 10 and total amount less than 500.
SELECT customer_id, COUNT(order_id), SUM(amount) FROM orders GROUP BY customer_id HAVING COUNT(order_id) [1] 10 AND SUM(amount) [2] 500;
We want customers with more than 10 orders (>) and total amount less than 500 (<).
Fill all three blanks to select departments with average salary above 50000, count of employees at least 5, and maximum salary below 100000.
SELECT department, AVG(salary), COUNT(*), MAX(salary) FROM employees GROUP BY department HAVING AVG(salary) [1] 50000 AND COUNT(*) [2] 5 AND MAX(salary) [3] 100000;
The conditions are: average salary > 50000, count >= 5, and max salary < 100000.