Bird
0
0

What will be the output of this query on table orders with column price?

medium📝 query result Q5 of 15
SQL - Aggregate Functions
What will be the output of this query on table orders with column price?
SELECT COUNT(price), SUM(price), AVG(price) FROM orders WHERE price > 100;
ACount, sum, and average of all prices including those ≤ 100
BOnly count of prices greater than 100
CSyntax error due to missing GROUP BY
DCount, sum, and average of prices greater than 100
Step-by-Step Solution
Solution:
  1. Step 1: Understand WHERE clause effect

    WHERE price > 100 filters rows before aggregation.
  2. Step 2: Aggregates apply on filtered rows

    COUNT, SUM, AVG calculate only on prices > 100.
  3. Final Answer:

    Count, sum, and average of prices greater than 100 -> Option D
  4. Quick Check:

    WHERE filters rows before aggregates [OK]
Quick Trick: WHERE filters rows before aggregates run [OK]
Common Mistakes:
MISTAKES
  • Thinking aggregates ignore WHERE filter
  • Expecting syntax error without GROUP BY
  • Assuming only one aggregate runs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes