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


OK, now that you know what the best salary is, let's discuss another function:

  AVG(TotalSum) AS AvgTotalSum
FROM Order
WHERE CustomerId = 100;

The AVG() function finds the average value of the specified column. In our example, we'll get the average order value for the customer with ID 100.

It is important to note that in SQL Server, AVG() used on an integer will use integer division and return an integer. For example, the average of the four numbers 1, 2, 2, and 2 will be 1 (even though it's 1.75 with floating-point division). Keep that in mind when you use AVG() on integer columns in SQL Server.


Find the average salary in the Employee table for the year 2013. Name the column AvgSalary.

Stuck? Here's a hint!


  AVG(Salary) AS AvgSalary
FROM Employee
WHERE Year = 2013;