Bird
0
0

How can you modify this query to find departments with average salary above 60000, excluding employees with salary below 30000?

hard📝 Application Q9 of 15
SQL - GROUP BY and HAVING
How can you modify this query to find departments with average salary above 60000, excluding employees with salary below 30000?
SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) > 60000;
ASELECT department, AVG(salary) FROM employees HAVING salary >= 30000 GROUP BY department HAVING AVG(salary) > 60000;
BSELECT department, AVG(salary) FROM employees GROUP BY department WHERE salary >= 30000 HAVING AVG(salary) > 60000;
CSELECT department, AVG(salary) FROM employees WHERE salary >= 30000 GROUP BY department HAVING AVG(salary) > 60000;
DSELECT department, AVG(salary) FROM employees WHERE AVG(salary) > 60000 AND salary >= 30000 GROUP BY department;
Step-by-Step Solution
Solution:
  1. Step 1: Use WHERE to exclude employees with salary below 30000

    WHERE filters rows before grouping to exclude low salaries.
  2. Step 2: Use HAVING to filter departments with average salary above 60000

    HAVING filters groups after aggregation.
  3. Final Answer:

    Filter rows with WHERE, groups with HAVING -> Option C
  4. Quick Check:

    Row filter = WHERE, group filter = HAVING [OK]
Quick Trick: Filter rows first with WHERE, then groups with HAVING [OK]
Common Mistakes:
MISTAKES
  • Using WHERE with aggregate
  • Placing WHERE after GROUP BY
  • Using HAVING to filter rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes