0
0
SQLquery~10 mins

GROUP BY with NULL values behavior in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to group rows by the column that may contain NULL values.

SQL
SELECT department, COUNT(*) FROM employees GROUP BY [1];
Drag options to blanks, or click blank then click option'
Ahire_date
Bsalary
Cemployee_id
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a column not in the SELECT list for grouping.
Using a column that does not relate to grouping by department.
2fill in blank
medium

Complete the code to count how many rows have NULL in the department column.

SQL
SELECT COUNT(*) FROM employees WHERE department [1] NULL;
Drag options to blanks, or click blank then click option'
A=
BIS
C!=
DLIKE
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' to compare with NULL.
Using 'LIKE' which is for pattern matching.
3fill in blank
hard

Fix the error in the GROUP BY clause to correctly group by department including NULLs.

SQL
SELECT department, COUNT(*) FROM employees GROUP BY [1];
Drag options to blanks, or click blank then click option'
ACOUNT(department)
Bdepartment IS NULL
Cdepartment
Ddepartment = NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using conditions like 'department IS NULL' in GROUP BY.
Using aggregate functions in GROUP BY.
4fill in blank
hard

Fill both blanks to group by department and replace NULL with 'Unknown' in the output.

SQL
SELECT COALESCE([1], 'Unknown') AS dept, COUNT(*) FROM employees GROUP BY [2];
Drag options to blanks, or click blank then click option'
Adepartment
Bsalary
Demployee_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using different columns in COALESCE and GROUP BY.
Trying to group by the COALESCE expression instead of the column.
5fill in blank
hard

Fill all three blanks to count employees grouped by department, showing 'No Dept' for NULLs and ordering by count descending.

SQL
SELECT COALESCE([1], [2]) AS dept, COUNT(*) AS total FROM employees GROUP BY [3] ORDER BY total DESC;
Drag options to blanks, or click blank then click option'
Adepartment
B'No Dept'
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by the COALESCE expression instead of the column.
Not replacing NULLs in the SELECT output.
Ordering by the wrong column.