Bird
0
0

Find the mistake in this SQL query:

medium📝 Debug Q7 of 15
SQL - GROUP BY and HAVING

Find the mistake in this SQL query:

SELECT department, COUNT(*) FROM employees WHERE COUNT(*) > 10 GROUP BY department;
ACOUNT(*) cannot be used in WHERE clause
BGROUP BY should come before WHERE
CCOUNT(*) should be replaced with SUM(*)
DNo mistake, query is valid
Step-by-Step Solution
Solution:
  1. Step 1: Understand WHERE limitations

    WHERE filters rows before aggregation and cannot use aggregate functions like COUNT.
  2. Step 2: Correct clause for aggregate filtering

    HAVING should be used to filter groups based on COUNT(*) > 10.
  3. Final Answer:

    COUNT(*) cannot be used in WHERE clause -> Option A
  4. Quick Check:

    Aggregate functions not allowed in WHERE = A [OK]
Quick Trick: Use HAVING, not WHERE, for aggregate filters [OK]
Common Mistakes:
MISTAKES
  • Using aggregate functions in WHERE clause
  • Confusing WHERE and HAVING roles

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes