0
0
SQLquery~5 mins

Aggregate with NULL handling in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ACOUNT(*)
BCOUNT(column)
CSUM(column)
DAVG(column)
What does SUM(column) do when the column contains NULL values?
AReturns NULL if any NULL exists
BIgnores NULLs and sums non-NULL values
CCounts NULLs as zero automatically
DThrows an error
How can you count only the rows where a column is NOT NULL?
ACOUNT(*)
BSUM(column)
CCOUNT(column)
DAVG(column)
Which SQL function can replace NULL with a specific value before aggregation?
AIFNULL()
BCOALESCE()
CNVL()
DAll of the above
What will AVG(column) return if all values in the column are NULL?
ANULL
B0
CError
D1
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.