Recall & Review
beginner
What happens to NULL values when using the COUNT(column) aggregate function in SQL?
COUNT(column) counts only non-NULL values in the specified column. NULL values are ignored.
Click to reveal answer
beginner
How does the SUM() function treat NULL values in SQL?
SUM() ignores NULL values and adds only the non-NULL numeric values.
Click to reveal answer
intermediate
What is the difference between COUNT(*) and COUNT(column) in handling NULLs?
COUNT(*) counts all rows regardless of NULLs, while COUNT(column) counts only rows where the column is NOT NULL.
Click to reveal answer
intermediate
How can you include NULL values as zero in aggregate calculations like SUM or AVG?
Use COALESCE(column, 0) to replace NULLs with zero before aggregation, e.g., SUM(COALESCE(column, 0)).
Click to reveal answer
advanced
Why is it important to handle NULLs explicitly in aggregate queries?
Because NULLs can cause aggregates like AVG or SUM to return unexpected results or skip data, handling NULLs ensures accurate calculations.
Click to reveal answer
Which aggregate function counts all rows including those with NULL values in any column?
✗ Incorrect
COUNT(*) counts every row regardless of NULLs in any column.
What does SUM(column) do when the column contains NULL values?
✗ Incorrect
SUM ignores NULL values and adds only the non-NULL numbers.
How can you count only the rows where a column is NOT NULL?
✗ Incorrect
COUNT(column) counts only rows where the column is NOT NULL.
Which SQL function can replace NULL with a specific value before aggregation?
✗ Incorrect
IFNULL, COALESCE, and NVL are functions used in different SQL dialects to replace NULLs.
What will AVG(column) return if all values in the column are NULL?
✗ Incorrect
AVG returns NULL if there are no non-NULL values to average.
Explain how NULL values affect aggregate functions like COUNT, SUM, and AVG in SQL.
Think about which aggregates count or sum NULLs and which do not.
You got /5 concepts.
Describe a method to include NULL values as zero in aggregate calculations and why it might be useful.
Consider how to treat missing data as zero for accurate sums or averages.
You got /4 concepts.