Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q14 of 15
SQL - GROUP BY and HAVING
Identify the error in this SQL query:
SELECT department, AVG(salary) FROM employees HAVING AVG(salary) > 50000 WHERE department LIKE 'Sales%' GROUP BY department;
AWHERE clause used after HAVING
BHAVING clause used before GROUP BY
CMissing alias for AVG(salary)
DGROUP BY clause missing
Step-by-Step Solution
Solution:
  1. Step 1: Check SQL clause order

    The correct order is WHERE, then GROUP BY, then HAVING.
  2. Step 2: Identify misplaced WHERE clause

    In the query, WHERE appears after HAVING, which is invalid syntax.
  3. Final Answer:

    WHERE clause used after HAVING -> Option A
  4. Quick Check:

    WHERE before GROUP BY, HAVING after [OK]
Quick Trick: WHERE before GROUP BY, HAVING after GROUP BY [OK]
Common Mistakes:
MISTAKES
  • Placing WHERE after HAVING
  • Forgetting GROUP BY clause
  • Using HAVING without GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes