Skip to content
Worked Examples · Example 8

Q.Using the Employee table, write SQL queries to find

(i) the total number of employees,
(ii) the total and average salary paid, and
(iii) the highest and lowest salary.
ChseodishaTextbookSubjectiveImportance★★★★★est
63% · 10/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 →

Each part uses an aggregate function over the whole Employee table.

(i) Number of employees — COUNT(*) counts all rows:

SELECT COUNT(*) AS TotalEmployees FROM Employee;

This gives 6.

(ii) Total and average salary — SUM and AVG of the Salary column. Both ignore the NULL salary, so the average is over the five known salaries:

SELECT SUM(Salary) AS TotalSalary, AVG(Salary) AS AverageSalary
FROM Employee;

The five known salaries are 25000 + 30000 + 28000 + 32000 + 40000 = 155000, so SUM is 155000 and AVG is 155000 / 5 = 31000.

(iii) Highest and lowest salary — MAX and MIN:

SELECT MAX(Salary) AS Highest, MIN(Salary) AS Lowest
FROM Employee;
``` …

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.