Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
SQL - GROUP BY and HAVING
What will be the output of this query?

SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) > 50000;
ASyntax error due to missing WHERE clause
BAll departments with their average salaries
CDepartments with average salary greater than 50000
DDepartments with total salary greater than 50000
Step-by-Step Solution
Solution:
  1. Step 1: Understand HAVING clause

    HAVING filters groups after aggregation, here filtering departments with average salary > 50000.
  2. Step 2: Analyze output

    Only departments meeting the condition appear with their average salary.
  3. Final Answer:

    Departments with average salary greater than 50000 -> Option C
  4. Quick Check:

    HAVING filters groups by aggregate condition [OK]
Quick Trick: Use HAVING to filter groups after aggregation [OK]
Common Mistakes:
MISTAKES
  • Confusing HAVING with WHERE
  • Expecting all departments without filtering
  • Thinking HAVING filters rows before grouping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes