Bird
0
0

Consider this query:

medium📝 Debug Q14 of 15
SQL - Aggregate Functions
Consider this query:
SELECT SUM(Price) FROM Products WHERE Category = 'Electronics'
It returns NULL instead of a number. What is the most likely cause?
AThere are no rows with Category = 'Electronics'
BThe Price column contains text values
CSUM() cannot be used with WHERE clause
DThe table Products does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Understand SUM() behavior with no matching rows

    If no rows match the WHERE condition, SUM() returns NULL.
  2. Step 2: Check other options

    Price with text would cause error, SUM() works with WHERE, and table missing causes error, not NULL.
  3. Final Answer:

    There are no rows with Category = 'Electronics' -> Option A
  4. Quick Check:

    SUM() returns NULL if no rows match [OK]
Quick Trick: SUM() returns NULL if no rows match WHERE [OK]
Common Mistakes:
MISTAKES
  • Assuming SUM() returns 0 when no rows match
  • Thinking SUM() fails with WHERE clause
  • Ignoring NULL result meaning no data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes