Skip to content
Worked Examples · Example 9

Q.Using the Employee table, write an SQL query to display each department along with the number of employees in it and the average salary of the department.

ChseodishaTextbookSubjectiveImportance★★★★★est
69% · 11/16 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

When a summary is wanted for each department separately, we use the GROUP BY clause to split the rows into groups sharing the same Dept, and then apply the aggregate functions to each group.

SELECT Dept, COUNT(*) AS NumEmployees, AVG(Salary) AS AvgSalary
FROM Employee
GROUP BY Dept;

The result has one row per department:

DeptNumEmployeesAvgSalary
Sales227500
Accounts230000
IT240000

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.