Complete the code to group rows by the column 'category'.
SELECT category, COUNT(*) FROM products [1] category;The GROUP BY clause groups rows that have the same values in specified columns. Here, it groups rows by 'category'.
Complete the code to filter groups having more than 5 items.
SELECT category, COUNT(*) FROM products GROUP BY category [1] COUNT(*) > 5;
The HAVING clause filters groups after aggregation. It is used to filter groups based on aggregate functions like COUNT.
Fix the error in the query by completing the blank with the correct clause.
SELECT category, price FROM products [1] category;This query selects 'category' and 'price' without aggregation. To sort rows by 'category', use ORDER BY. Using GROUP BY without aggregation causes an error.
Fill both blanks to group by 'department' and filter groups with average salary above 50000.
SELECT department, AVG(salary) FROM employees [1] department [2] AVG(salary) > 50000;
First, use GROUP BY to group rows by 'department'. Then, use HAVING to filter groups where the average salary is greater than 50000.
Fill all three blanks to select department names in uppercase, average salary as avg_sal, and filter groups with avg_sal above 60000.
SELECT [1], AVG(salary) AS [2] FROM employees [3] department HAVING AVG(salary) > 60000;
Use UPPER(department) to show department names in uppercase. Alias the average salary as avg_sal. Group rows by department using GROUP BY before filtering with HAVING.