Complete the code to group rows by the column that may contain NULL values.
SELECT department, COUNT(*) FROM employees GROUP BY [1];The GROUP BY clause groups rows by the specified column. Here, grouping by department groups employees by their department, including those with NULL values.
Complete the code to count how many rows have NULL in the department column.
SELECT COUNT(*) FROM employees WHERE department [1] NULL;To check for NULL values in SQL, use IS NULL. Using = NULL does not work because NULL means unknown.
Fix the error in the GROUP BY clause to correctly group by department including NULLs.
SELECT department, COUNT(*) FROM employees GROUP BY [1];The GROUP BY clause must use the column name directly. Expressions like department IS NULL or comparisons with NULL are invalid here.
Fill both blanks to group by department and replace NULL with 'Unknown' in the output.
SELECT COALESCE([1], 'Unknown') AS dept, COUNT(*) FROM employees GROUP BY [2];
COALESCE(department, 'Unknown') replaces NULL with 'Unknown' in the output. The GROUP BY must use the original column department to group rows correctly.
Fill all three blanks to count employees grouped by department, showing 'No Dept' for NULLs and ordering by count descending.
SELECT COALESCE([1], [2]) AS dept, COUNT(*) AS total FROM employees GROUP BY [3] ORDER BY total DESC;
Use COALESCE(department, 'No Dept') to replace NULLs with 'No Dept'. Group by the original department column. Ordering by total DESC shows groups with most employees first.