0
0
SQLquery~20 mins

NULL behavior in aggregate functions in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NULL Mastery in Aggregates
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of COUNT with NULL values
Consider a table Employees with a column Bonus that contains some NULL values. What is the output of the following query?
SELECT COUNT(Bonus) FROM Employees;
SQL
CREATE TABLE Employees (ID INT, Bonus INT);
INSERT INTO Employees VALUES (1, 100), (2, NULL), (3, 200), (4, NULL);
A2
B4
C0
DNULL
Attempts:
2 left
💡 Hint
COUNT(column) counts only non-NULL values.
query_result
intermediate
2:00remaining
SUM ignoring NULL values
Given a table Sales with a column Amount containing some NULLs, what is the output of this query?
SELECT SUM(Amount) FROM Sales;
SQL
CREATE TABLE Sales (ID INT, Amount INT);
INSERT INTO Sales VALUES (1, 50), (2, NULL), (3, 150), (4, NULL);
ANULL
B200
C0
D50
Attempts:
2 left
💡 Hint
SUM ignores NULL values and sums only non-NULL entries.
🧠 Conceptual
advanced
2:00remaining
Behavior of AVG with NULL values
Which statement correctly describes how the AVG aggregate function treats NULL values in a column?
AAVG includes NULL values as zero in the calculation.
BAVG returns NULL if any NULL values exist in the column.
CAVG ignores NULL values and calculates the average of non-NULL values only.
DAVG counts NULL values as one in the denominator.
Attempts:
2 left
💡 Hint
Think about how average is calculated when some values are missing.
query_result
advanced
2:00remaining
MIN function with all NULL values
What is the output of this query when all values in the Score column are NULL?
SELECT MIN(Score) FROM Results;
SQL
CREATE TABLE Results (ID INT, Score INT);
INSERT INTO Results VALUES (1, NULL), (2, NULL), (3, NULL);
AMinimum integer value
B0
CError
DNULL
Attempts:
2 left
💡 Hint
MIN returns NULL if no non-NULL values exist.
query_result
expert
2:00remaining
Aggregate functions and NULL in WHERE clause
Consider a table Orders with a column Discount that contains some NULL values. What is the output of the following query?
SELECT AVG(Discount) FROM Orders WHERE Discount > 10;
SQL
CREATE TABLE Orders (ID INT, Discount INT);
INSERT INTO Orders VALUES (1, 5), (2, NULL), (3, 20), (4, NULL), (5, 10), (6, 30);
A25
BNULL
CError
D0
Attempts:
2 left
💡 Hint
NULL > 10 evaluates to UNKNOWN (not true), so rows with NULL are excluded. AVG is then computed on qualifying non-NULL values.