Bird
0
0

How can you find the department with the highest average salary using aggregation?

hard📝 Application Q9 of 15
SQL - Aggregate Functions
How can you find the department with the highest average salary using aggregation?
ASELECT Department, MAX(AVG(Salary)) FROM Employees GROUP BY Department;
BSELECT Department FROM Employees GROUP BY Department ORDER BY AVG(Salary) DESC LIMIT 1;
CSELECT Department, AVG(Salary) FROM Employees WHERE AVG(Salary) = MAX(AVG(Salary));
DSELECT Department FROM Employees WHERE Salary = MAX(Salary);
Step-by-Step Solution
Solution:
  1. Step 1: Calculate average salary per department

    GROUP BY Department with AVG(Salary) computes average salaries.
  2. Step 2: Order results to find highest average

    ORDER BY AVG(Salary) DESC sorts from highest to lowest average salary.
  3. Step 3: Limit to top result

    LIMIT 1 returns only the department with the highest average salary.
  4. Final Answer:

    SELECT Department FROM Employees GROUP BY Department ORDER BY AVG(Salary) DESC LIMIT 1; -> Option B
  5. Quick Check:

    Use ORDER BY AVG() DESC with LIMIT 1 to find max average [OK]
Quick Trick: Order by AVG() DESC and limit 1 finds highest average [OK]
Common Mistakes:
MISTAKES
  • Trying to nest MAX(AVG()) which is invalid
  • Using WHERE with aggregate functions
  • Selecting without grouping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes