Bird
0
0

Find the mistake in this query: SELECT AVG(price), MIN(price), MAX(price) FROM products GROUP BY price;

medium📝 Debug Q7 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Find the mistake in this query: SELECT AVG(price), MIN(price), MAX(price) FROM products GROUP BY price;
AMissing WHERE clause
BGROUP BY price causes each group to have one price, making AVG redundant
CAVG requires a HAVING clause
DMIN and MAX cannot be used with GROUP BY
Step-by-Step Solution
Solution:
  1. Step 1: Analyze GROUP BY effect

    Grouping by price means each group has one price value.
  2. Step 2: Understand AVG behavior

    AVG(price) over single-value groups equals that value, so AVG is redundant.
  3. Final Answer:

    GROUP BY price causes each group to have one price, making AVG redundant -> Option B
  4. Quick Check:

    GROUP BY price groups single values [OK]
Quick Trick: GROUP BY single column makes aggregates trivial [OK]
Common Mistakes:
  • Thinking MIN/MAX disallowed with GROUP BY
  • Requiring HAVING for AVG
  • Expecting WHERE needed always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes