Bird
0
0

What is wrong with this SQL query if we want to find the average salary per department?

medium📝 Debug Q14 of 15
SQL - Aggregate Functions
What is wrong with this SQL query if we want to find the average salary per department?
SELECT Department, AVG(Salary) FROM Employees;
AAVG() cannot be used on Salary
BMissing GROUP BY clause for Department
CSELECT must include only one column
DSalary column name is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check aggregation with multiple columns

    When selecting Department and AVG(Salary), Department must be grouped.
  2. Step 2: Identify missing GROUP BY

    The query lacks GROUP BY Department, causing error or wrong results.
  3. Final Answer:

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

    Aggregation with columns needs GROUP BY [OK]
Quick Trick: Use GROUP BY when mixing columns with aggregation [OK]
Common Mistakes:
MISTAKES
  • Forgetting GROUP BY with aggregation
  • Thinking AVG() can't be used on numbers
  • Assuming SELECT can have unrelated columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes