SQL Output Prediction Hard +35 XP
GROUP BY with HAVING
What does this query do?
SQLRead-only
SELECT department, AVG(salary) AS avg_sal FROM employees GROUP BY department HAVING AVG(salary) > 50000 ORDER BY avg_sal DESC;
What is the output?
Show answer and explanation
Answer: Departments with avg salary > 50k, sorted highest first
GROUP BY groups by dept, HAVING filters groups where avg salary > 50k, ORDER BY DESC sorts highest first.
Hint: HAVING filters groups, not rows.
What this challenge tests
Output Prediction in SQL: group-by, having, aggregate.