Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
Limiting the output
Eliminating duplicate results
Aggregation
Grouping
20. Find the average value in groups
HAVING: filtering and ordering groups
Let's practice

Instruction

Well done! Let's study one more example of this kind:

SELECT
  CustomerId,
  AVG(TotalSum) AS AvgCustomerTotal
FROM Order
GROUP BY CustomerId;

As you can see, we now have the function AVG(TotalSum), which will count the average order value for each customer.

Exercise

Find the average salary for each department in 2015. Name the column AvgDepartmentSalary.

Stuck? Here's a hint!

Type:

SELECT
  Department,
  AVG(Salary) AS AvgDepartmentSalary
FROM Employee
WHERE Year = 2015
GROUP BY department;