Bird
0
0

Given the table orders with column discount containing values (10, NULL, 10, NULL, 15), what is the result of this query?

medium📝 query result Q13 of 15
SQL - Aggregate Functions
Given the table orders with column discount containing values (10, NULL, 10, NULL, 15), what is the result of this query?
SELECT AVG(COALESCE(discount, 0)) FROM orders;
A7
B10
C15
DNULL
Step-by-Step Solution
Solution:
  1. Step 1: Replace NULLs with 0 using COALESCE

    Values become 10, 0, 10, 0, 15.
  2. Step 2: Calculate average of these values

    Sum = 10 + 0 + 10 + 0 + 15 = 35; Count = 5; Average = 35 / 5 = 7.
  3. Final Answer:

    7 -> Option A
  4. Quick Check:

    COALESCE replaces NULLs, AVG includes zeros [OK]
Quick Trick: Replace NULLs with zero before AVG to include them [OK]
Common Mistakes:
MISTAKES
  • Ignoring NULLs and averaging only non-NULL values
  • Assuming AVG ignores zeros
  • Miscounting number of rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes