Bird
0
0

Find the error in this query:

medium📝 Debug Q6 of 15
SQL - GROUP BY and HAVING
Find the error in this query:
SELECT team, AVG(score) FROM players WHERE AVG(score) > 80 GROUP BY team;
AMissing GROUP BY clause
BUsing AVG(score) in WHERE clause
CIncorrect SELECT syntax
DHAVING clause missing after GROUP BY
Step-by-Step Solution
Solution:
  1. Step 1: Identify WHERE clause limitations

    WHERE cannot use aggregate functions like AVG because it filters rows before aggregation.
  2. Step 2: Correct clause usage

    To filter groups by AVG(score), use HAVING instead of WHERE.
  3. Final Answer:

    Using AVG(score) in WHERE clause -> Option B
  4. Quick Check:

    Aggregate filters require HAVING, not WHERE [OK]
Quick Trick: Aggregate functions cannot be used in WHERE clause [OK]
Common Mistakes:
MISTAKES
  • Placing aggregate conditions in WHERE
  • Omitting HAVING after GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes