Bird
0
0

Identify the error in this query:

medium📝 Debug Q14 of 15
SQL - GROUP BY and HAVING
Identify the error in this query:
SELECT department, COUNT(employee_id) FROM employees;
ASELECT must include WHERE clause
BMissing GROUP BY clause for department
CCOUNT cannot be used with employee_id
Demployee_id should be in HAVING clause
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the SELECT and aggregation

    The query selects department and counts employee_id but lacks grouping.
  2. Step 2: Understand SQL rules for aggregation

    When using aggregate functions with other columns, those columns must be in GROUP BY.
  3. Final Answer:

    Missing GROUP BY clause for department -> Option B
  4. Quick Check:

    Aggregate + column needs GROUP BY [OK]
Quick Trick: Use GROUP BY with non-aggregated columns [OK]
Common Mistakes:
MISTAKES
  • Omitting GROUP BY with aggregates
  • Misusing HAVING for columns
  • Thinking COUNT can't use column names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes