Bird
0
0

Consider this query:

medium📝 Debug Q14 of 15
SQL - Aggregate Functions
Consider this query:
SELECT AVG(price) FROM Products WHERE price > 0;
It returns NULL even though there are products with price 0 and above. What is the likely problem?
AThe WHERE clause excludes all rows because price > 0 filters out zero prices
BAVG() cannot be used with WHERE clause
CThe price column contains only NULL values
DAVG() requires GROUP BY to work
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the WHERE clause condition

    The condition price > 0 excludes prices equal to zero, so only prices greater than zero are included.
  2. Step 2: Consider data and NULL result

    If no prices are greater than zero, the filtered set is empty, so AVG() returns NULL.
  3. Final Answer:

    The WHERE clause excludes all rows because price > 0 filters out zero prices -> Option A
  4. Quick Check:

    Empty filtered rows cause AVG() to return NULL [OK]
Quick Trick: Check WHERE filters exclude all rows causing NULL AVG() [OK]
Common Mistakes:
MISTAKES
  • Thinking AVG() can't use WHERE
  • Assuming AVG() needs GROUP BY always
  • Ignoring that empty sets return NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes