Complete the code to filter groups having more than 3 orders.
SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id HAVING COUNT(*) [1] 3;
The HAVING clause filters groups where the count of orders is greater than 3.
Complete the code to select product categories with total sales equal to 1000.
SELECT category, SUM(sales) FROM products GROUP BY category HAVING SUM(sales) [1] 1000;
The HAVING clause filters groups where the total sales exactly equal 1000.
Fix the error in the code to filter groups with average rating at least 4.
SELECT product_id, AVG(rating) FROM reviews GROUP BY product_id HAVING AVG(rating) [1] 4;
The HAVING clause filters groups where the average rating is greater than or equal to 4.
Fill both blanks to select departments with more than 5 employees and total salary less than 50000.
SELECT department, COUNT(*) AS emp_count, SUM(salary) AS total_salary FROM employees GROUP BY department HAVING COUNT(*) [1] 5 AND SUM(salary) [2] 50000;
The HAVING clause filters departments with employee count greater than 5 and total salary less than 50000.
Fill all three blanks to select cities with average temperature above 20, count of days above 10, and max temperature below 35.
SELECT city, AVG(temperature) AS avg_temp, COUNT(*) AS hot_days, MAX(temperature) AS max_temp FROM weather GROUP BY city HAVING AVG(temperature) [1] 20 AND COUNT(*) [2] 10 AND MAX(temperature) [3] 35;
The HAVING clause filters cities where average temperature is above 20, count of days is at least 10, and max temperature is below 35.